setting the timezone for a user's session on login instead of every request checking and setting

This commit is contained in:
Brian 2022-05-20 13:51:37 -06:00
parent b87104c22d
commit 6241539cb3
Signed by: brian
GPG Key ID: DE1A5390A3B84CD8
3 changed files with 117 additions and 0 deletions

View 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);
}
}

View 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');
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace App\Providers;
use App\Listeners\SuccessfulLogin;
//use App\Listeners\SuccessfulLogout;
use Illuminate\Auth\Events\Login;
//use Illuminate\Auth\Events\Logout;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
Login::class => [
SuccessfulLogin::class,
],
/*Logout::class => [
SuccessfulLogout::class,
],*/
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}