setting the timezone for a user's session on login instead of every request checking and setting
This commit is contained in:
33
src/app/Listeners/SuccessfulLogin.php
Normal file
33
src/app/Listeners/SuccessfulLogin.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class SuccessfulLogin
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \Illuminate\Auth\Events\Login $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Login $event): void
|
||||
{
|
||||
Session::put('timezone_name', $event->user->timezone_name);
|
||||
}
|
||||
}
|
32
src/app/Listeners/SuccessfulLogout.php
Normal file
32
src/app/Listeners/SuccessfulLogout.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Logout;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class SuccessfulLogout
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \Illuminate\Auth\Events\Logout $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Logout $event)
|
||||
{
|
||||
Session::forget('timezone_name');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user