auth activity done

This commit is contained in:
2024-01-30 23:28:49 +05:00
parent a093230287
commit b3d9545900
4 changed files with 102 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Listeners;
use Illuminate\Support\Facades\Log;
class LoginListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param object $event
*/
public function handle($event): void
{
$user = $event->user;
if (! $user) {
return;
}
Log::channel('auth_activity')
->info(sprintf(
'%s, APP_NAME: %s, REQUEST_TYPE: %s, SOURCE_IP: %s, SOURCE_PORT: %s, SOURCE_URL: %s, DESTINATION_IP: %s, DESTINATION_PORT: %s, DESTINATION_COUNTRY: %s',
'LOGIN',
config('app.name'),
request()->method(),
request()->ip(),
$_SERVER['REMOTE_PORT'],
request()->url(),
request()->host(),
request()->getPort(),
'tk',
));
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Listeners;
use Illuminate\Support\Facades\Log;
class LogoutListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
$user = $event->user;
if (! $user) {
return;
}
Log::channel('auth_activity')
->info(sprintf(
'%s, APP_NAME: %s, REQUEST_TYPE: %s, SOURCE_IP: %s, SOURCE_PORT: %s, SOURCE_URL: %s, DESTINATION_IP: %s, DESTINATION_PORT: %s, DESTINATION_COUNTRY: %s',
'LOGOUT',
config('app.name'),
request()->method(),
request()->ip(),
$_SERVER['REMOTE_PORT'],
request()->url(),
request()->host(),
request()->getPort(),
'tk',
));
}
}

View File

@@ -2,8 +2,6 @@
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
@@ -15,9 +13,8 @@ class EventServiceProvider extends ServiceProvider
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'Illuminate\Auth\Events\Login' => ['App\Listeners\LoginListener'],
'Illuminate\Auth\Events\Logout' => ['App\Listeners\LogoutListener'],
];
/**

View File

@@ -127,6 +127,13 @@ return [
'path' => storage_path('logs/laravel.log'),
],
'auth_activity' => [
'driver' => 'single',
'path' => storage_path('logs/auth_activity.log'),
'level' => 'info',
'replace_placeholders' => true,
],
'halkbank_payment_error' => [
'driver' => 'single',
'path' => storage_path('logs/halkbank_payment_error.log'),