fix(pg,auth): prevent deactivated security guards from logging in and accessing pg module

This commit is contained in:
Ray1111-aa
2026-11-03 12:03:16 +07:00
parent 6e5c6eeeb8
commit c1be96c2ba
4 changed files with 53 additions and 0 deletions
+6
View File
@@ -27,6 +27,12 @@ class CheckRole
return $next($request);
}
// Proteksi: Cek apakah petugas satpam berstatus Nonaktif
$guard = $user->securityGuard ?: \App\Models\SecurityGuard::where('user_id', $user->id)->first();
if ($guard && ! $guard->is_active) {
abort(403, 'Akses Ditolak: Akun Petugas Satpam Anda berstatus Nonaktif. Silakan hubungi Administrator PG.');
}
// Cek via kolom role string atau Spatie hasAnyRole
if (in_array($userRole, $roles) || (method_exists($user, 'hasAnyRole') && $user->hasAnyRole($roles))) {
return $next($request);