-
Notifications
You must be signed in to change notification settings - Fork 143
[Add] Menambah fitur Log Activity #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
f141b0a
58c173a
636144b
9a6a2c3
0a3d0fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,14 +31,15 @@ | |
|
|
||
| namespace App\Http\Controllers\Auth; | ||
|
|
||
| use App\Http\Controllers\Controller; | ||
| use App\Models\User; | ||
| use App\Notifications\SendToken2FA; | ||
| use App\Providers\RouteServiceProvider; | ||
| use App\Http\Controllers\Controller; | ||
| use Illuminate\Foundation\Auth\AuthenticatesUsers; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\Hash; | ||
| use Illuminate\Support\Facades\View; | ||
| use App\Services\ActivityLogger; | ||
|
|
||
| class LoginController extends Controller | ||
| { | ||
|
|
@@ -53,7 +54,9 @@ class LoginController extends Controller | |
| | | ||
| */ | ||
|
|
||
| use AuthenticatesUsers; | ||
| use AuthenticatesUsers { | ||
| sendFailedLoginResponse as traitSendFailedLoginResponse; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] 🐛 Bug: ActivityLogger Exception Menghentikan Login Flow Kode: Skenario: Dampak:
Fix: protected function authenticated(Request $request, $user)
{
try {
ActivityLogger::log('login', "Pengguna {$user->name} berhasil login", $user, 'success');
} catch (\Exception $e) {
report($e);
// Jangan crash login flow
}
return redirect()->intended($this->redirectPath());
} |
||
| } | ||
|
|
||
| /** | ||
| * Where to redirect users after login. | ||
|
|
@@ -134,13 +137,92 @@ protected function validateLogin(Request $request) | |
| } | ||
| protected function authenticated(Request $request, $user) | ||
| { | ||
| // Log successful login | ||
| ActivityLogger::log( | ||
| category: 'login', | ||
| event: 'success', | ||
| message: 'Pengguna berhasil masuk ke sistem', | ||
| subject: $user, | ||
| causer: $user, | ||
| additionalProperties: [ | ||
| 'user_id' => $user->id, | ||
| 'email' => $user->email, | ||
| 'status' => 'authenticated', | ||
| ] | ||
| ); | ||
|
|
||
| if (($this->settings['login_2fa'] ?? false)) { | ||
| return $this->startTwoFactorAuthProcess($request, $user); | ||
| } | ||
|
|
||
| return redirect()->intended($this->redirectPath()); | ||
| } | ||
|
|
||
| /** | ||
| * Handle a failed authentication attempt. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @return void | ||
| * | ||
| * @throws \Illuminate\Validation\ValidationException | ||
| */ | ||
| protected function sendFailedLoginResponse(Request $request) | ||
| { | ||
| // Log failed login attempt | ||
| ActivityLogger::log( | ||
| category: 'login', | ||
| event: 'failed', | ||
| message: 'Percobaan login gagal', | ||
| subject: null, | ||
| causer: null, | ||
| additionalProperties: [ | ||
| 'email' => $request->input($this->username()), | ||
| 'status' => 'invalid_credentials', | ||
| ] | ||
| ); | ||
|
|
||
| return $this->traitSendFailedLoginResponse($request); | ||
| } | ||
|
|
||
| /** | ||
| * The user has logged out of the application. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @return mixed | ||
| */ | ||
| public function logout(Request $request) | ||
| { | ||
| // Log the logout event before logging out | ||
| if (auth()->check()) { | ||
| ActivityLogger::log( | ||
| category: 'login', | ||
| event: 'logout', | ||
| message: 'Pengguna keluar dari sistem', | ||
| subject: auth()->user(), | ||
| causer: auth()->user(), | ||
| additionalProperties: [ | ||
| 'user_id' => auth()->id(), | ||
| 'email' => auth()->user()->email ?? null, | ||
| 'status' => 'logged_out', | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| $this->guard()->logout(); | ||
|
|
||
| $request->session()->invalidate(); | ||
|
|
||
| $request->session()->regenerateToken(); | ||
|
|
||
| return $this->loggedOut($request) ?: redirect('/'); | ||
| } | ||
|
|
||
| protected function loggedOut(Request $request) | ||
| { | ||
| // This method can be used for additional logic after logout | ||
| // For example, flashing a session message. | ||
| } | ||
|
|
||
| /** | ||
| * Log out the user and start the two factor authentication state. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] 🐛 Bug: Auth::user() Null Dereference - Fatal Error Setelah Login
Kode:
Skenario: Race condition dimana user berhasil authenticate tapi kemudian dihapus/disabled sebelum
Auth::user()dipanggil.$userakan null, akses$user->namemenyebabkan fatal error "Trying to get property 'name' of null".Dampak:
Fix: