fix logout issue
This commit is contained in:
@@ -123,23 +123,17 @@ class LoginController extends Controller
|
||||
{
|
||||
$user = Auth::guard('admin')->user();
|
||||
|
||||
if (!$user) {
|
||||
Auth::guard('admin')->logout();
|
||||
return redirect()->route('admin.login');
|
||||
if ($user) {
|
||||
// Log activity hanya jika user valid
|
||||
AuditTrailHelper::AuthAttempt('Logout', 'User (' . $user->username . ') Logged out from the System');
|
||||
}
|
||||
|
||||
// Log activity
|
||||
AuditTrailHelper::AuthAttempt('Logout', 'User (' . $user->username . ') Logged out from the System');
|
||||
|
||||
try {
|
||||
// Logout from admin guard
|
||||
Auth::guard('admin')->logout();
|
||||
} catch (Exception $e) {
|
||||
// Fallback to web guard if admin logout fails
|
||||
Auth::guard('web')->logout();
|
||||
}
|
||||
|
||||
// Redirect to admin login
|
||||
return redirect()->route('admin.login');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Models\LoginLog;
|
||||
|
||||
class LogLoginActivity
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(Login $event): void
|
||||
{
|
||||
// Ambil data user yang login
|
||||
$user = $event->user;
|
||||
|
||||
// Simpan log login
|
||||
LoginLog::create([
|
||||
'user_id' => $user->id ?? null,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
'status' => 'login',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Logout;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Models\LoginLog;
|
||||
|
||||
class LogLogoutActivity
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(Logout $event): void
|
||||
{
|
||||
// Ambil data user yang logout
|
||||
$user = $event->user;
|
||||
|
||||
// Simpan log logout
|
||||
LoginLog::create([
|
||||
'user_id' => $user->id ?? null,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
'status' => 'logout', // Kolom tambahan untuk menandakan logout
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
\Illuminate\Auth\Events\Login::class => [
|
||||
\App\Listeners\LogLoginActivity::class,
|
||||
],
|
||||
\Illuminate\Auth\Events\Logout::class => [
|
||||
\App\Listeners\LogLogoutActivity::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user