From 35a5ec6c119c5acc8f25997187affd228d680ffb Mon Sep 17 00:00:00 2001 From: Sam Light Date: Thu, 10 Apr 2025 00:40:03 +0100 Subject: Created AuthSubscriber to listener to auth events and log them --- src/AuthSubscriber.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/AuthSubscriber.php diff --git a/src/AuthSubscriber.php b/src/AuthSubscriber.php new file mode 100644 index 0000000..6d4cc63 --- /dev/null +++ b/src/AuthSubscriber.php @@ -0,0 +1,48 @@ + $status, + ]); + $log->user()->associate($event->user); + $log->save(); + } + + public function handleLogin(Login $event): void + { + $this->handleEvent(Status::LoginSuccess, $event); + } + + public function handleFailed(Failed $event): void + { + $this->handleEvent(Status::LoginFailure, $event); + } + + public function handleLogout(Logout $event): void + { + $this->handleEvent(Status::Logout, $event); + } + + public function subscribe(Dispatcher $events): array + { + return [ + Login::class => 'handleLogin', + Failed::class => 'handleFailed', + Logout::class => 'handleLogout', + ]; + } +} -- cgit v1.2.3