Skip to content

Commit

Permalink
Merge pull request #185 from kangketikonlen/061124-024117
Browse files Browse the repository at this point in the history
[06-11-2024 02:42] 061124-024117 - Request merge 061124-024117 to stable branch
  • Loading branch information
kangketikonlen authored Nov 5, 2024
2 parents ce65663 + 59620e3 commit ae01d48
Show file tree
Hide file tree
Showing 49 changed files with 524 additions and 400 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\System\Module;
use App\Models\System\ModuleCustom;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

class DashboardController extends Controller
Expand Down Expand Up @@ -70,7 +71,7 @@ public function switch_task(Request $request): RedirectResponse

public function reset(): RedirectResponse
{
$user = auth()->user();
$user = Auth::user();
$session = array(
'role_id' => $user?->role_id,
'role_name' => $user?->roles?->name,
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/PortalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\System\AppInfo;
use App\Models\System\Institution;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\View\View;

Expand All @@ -25,9 +26,9 @@ public function auth(Request $request): RedirectResponse
'password' => 'required'
]);

if (auth()->attempt($formFields)) {
if (Auth::attempt($formFields)) {
$request->session()->regenerate();
$user = auth()->user();
$user = Auth::user();

// Create session
$session = array(
Expand Down Expand Up @@ -57,7 +58,7 @@ public function logout(Request $request): RedirectResponse

private function invalidate_session(Request $request): void
{
auth()->logout();
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
$request->session()->flush();
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class ProfileController extends Controller
Expand All @@ -13,7 +14,7 @@ class ProfileController extends Controller

public function index(): View
{
$data['user'] = auth()->user();
$data['user'] = Auth::user();
return view('pages.profile', $data);
}

Expand All @@ -33,7 +34,7 @@ public function update(Request $request): RedirectResponse
$formFields['picture'] = '/storage/images/profile/' . $filename;
}

$user = User::find(auth()->user()?->id);
$user = User::find(Auth::user()?->id);
$user?->update($formFields);

$this->invalidate_session($request);
Expand All @@ -48,15 +49,15 @@ public function reset(): RedirectResponse
$newPassword = "USR" . $serialCode . "P";

$hashedPassword['password'] = bcrypt($newPassword);
$user = User::find(auth()->user()?->id);
$user = User::find(Auth::user()?->id);
$user?->update($hashedPassword);

return redirect($this->url)->with('alert', ['message' => 'Password has been reset, your new password is ' . $newPassword, 'status' => 'success']);
}

private function invalidate_session(Request $request): void
{
auth()->logout();
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
$request->session()->flush();
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/Report/ActivityLogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers\Report;

use Illuminate\Http\Request;
use App\Models\System\ActivityLog;
use App\Http\Controllers\Controller;
use Illuminate\View\View;

class ActivityLogController extends Controller
{
protected string $url = "/report/activity-log";

public function index(Request $request): View
{
$activityLogs = ActivityLog::orderBy('id', 'desc');
$dateStart = $request->input('dateStart');
$dateEnd = $request->input('dateEnd');

if (!empty($dateStart)) {
$activityLogs->whereBetween('date', [$dateStart, $dateEnd]);
}

$data['query'] = $request->input('query');
$data['activityLog'] = $activityLogs->paginate(10)->appends($request->query());
return view('pages.report.activity-log.index', $data);
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/Report/ErrorLogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers\Report;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ErrorLogController extends Controller
{
public function index(Request $request)
{
return view('pages.report.error-log.index');
}
}
2 changes: 0 additions & 2 deletions app/Http/Controllers/Setting/InstitutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Http\Controllers\Setting;

use Illuminate\View\View;
use Intervention\Image\ImageManagerStatic as Image;
use App\Models\System\Institution;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use App\Http\Requests\Institution\UpdateInstitutionRequest;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\ActivityLogMiddleware::class,
],

'api' => [
Expand Down
57 changes: 57 additions & 0 deletions app/Http/Middleware/ActivityLogMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use App\Models\System\ActivityLog;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class ActivityLogMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$auth = Auth::check();
$path = $request->path();

if ($auth) {
$logData['session_id'] = $request->session()->getId();
$logData['date'] = date("Y-m-d");
$logData['time'] = date("H:i:s");
$logData['ip_address'] = $request->ip();
$logData['method'] = $request->method();
$logData['referer'] = $request->headers->get('referer');

if ($path == "/") {
$logData['path'] = "portal";
} else {
$logData['path'] = $path;
}

$logData['user'] = Auth::user()?->name;
$logData['role'] = Auth::user()?->roles?->name;
$logData['description'] = $logData['user'] . " (" . $logData['ip_address'] . ") telah mendarat di halaman " . $logData['path'];

$activityLog = ActivityLog::where('date', $logData['date'])->where('session_id', $logData['session_id'])->where('path', $logData['path'])->first();

if ($logData['path'] != "dashboard") {
if (empty($activityLog)) {
ActivityLog::create($logData);
} else {
$newLogData['time'] = date("H:i:s");

$activityLog->increment('totalHit');
$activityLog->update($newLogData);
}
}
}

return $next($request);
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
$user = auth()->user();
$user = Auth::user();
$url = $user?->roles?->dashboard_url;

return redirect($url);
Expand Down
25 changes: 25 additions & 0 deletions app/Models/System/ActivityLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Models\System;

use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class ActivityLog extends Model
{
use HasFactory;

protected static function boot()
{
parent::boot();

static::creating(function ($model) {
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
7 changes: 3 additions & 4 deletions app/Models/System/AppInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class AppInfo extends Model
{
Expand All @@ -14,13 +15,11 @@ protected static function boot()
parent::boot();

static::creating(function ($model) {
$model->createdAt = $model->freshTimestamp();
$model->createdBy = auth()->check() ? session('name') : "System";
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updatedAt = $model->freshTimestamp();
$model->updatedBy = auth()->check() ? session('name') : "System";
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
7 changes: 3 additions & 4 deletions app/Models/System/Institution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class Institution extends Model
{
Expand All @@ -14,13 +15,11 @@ protected static function boot()
parent::boot();

static::creating(function ($model) {
$model->createdAt = $model->freshTimestamp();
$model->createdBy = auth()->check() ? session('name') : "System";
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updatedAt = $model->freshTimestamp();
$model->updatedBy = auth()->check() ? session('name') : "System";
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
7 changes: 3 additions & 4 deletions app/Models/System/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Auth;

class Module extends Model
{
Expand All @@ -14,13 +15,11 @@ protected static function boot()
parent::boot();

static::creating(function ($model) {
$model->createdAt = $model->freshTimestamp();
$model->createdBy = auth()->check() ? session('name') : "System";
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updatedAt = $model->freshTimestamp();
$model->updatedBy = auth()->check() ? session('name') : "System";
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
7 changes: 3 additions & 4 deletions app/Models/System/ModuleCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Auth;

class ModuleCustom extends Model
{
Expand All @@ -20,13 +21,11 @@ protected static function boot()
parent::boot();

static::creating(function ($model) {
$model->createdAt = $model->freshTimestamp();
$model->createdBy = auth()->check() ? session('name') : "System";
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updatedAt = $model->freshTimestamp();
$model->updatedBy = auth()->check() ? session('name') : "System";
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
7 changes: 3 additions & 4 deletions app/Models/System/ModuleCustomUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Auth;

class ModuleCustomUser extends Model
{
Expand All @@ -26,13 +27,11 @@ protected static function boot()
parent::boot();

static::creating(function ($model) {
$model->createdAt = $model->freshTimestamp();
$model->createdBy = auth()->check() ? session('name') : "System";
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updatedAt = $model->freshTimestamp();
$model->updatedBy = auth()->check() ? session('name') : "System";
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
7 changes: 3 additions & 4 deletions app/Models/System/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Auth;

class Navbar extends Model
{
Expand All @@ -21,13 +22,11 @@ protected static function boot()
parent::boot();

static::creating(function ($model) {
$model->createdAt = $model->freshTimestamp();
$model->createdBy = auth()->check() ? session('name') : "System";
$model->created_by = Auth::check() ? session('name') : "System";
});

static::updating(function ($model) {
$model->updatedAt = $model->freshTimestamp();
$model->updatedBy = auth()->check() ? session('name') : "System";
$model->updated_by = Auth::check() ? session('name') : null;
});
}
}
Loading

0 comments on commit ae01d48

Please sign in to comment.