Skip to content

Commit

Permalink
Check for AuthenticationLoggable trait on event
Browse files Browse the repository at this point in the history
  • Loading branch information
rappasoft committed Mar 29, 2024
1 parent c901975 commit 0967d3a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ All notable changes to `Laravel Authentication Log` will be documented in this f
### 4.0.0 - 2024-03-28

- Laravel 11 Support (https://github.com/rappasoft/laravel-authentication-log/pull/100)
- Add config listeners
- Add config listeners (https://github.com/rappasoft/laravel-authentication-log/pull/92)
- Use real user IP behind Cloudflare
- Check for AuthenticationLoggable trait on event (https://github.com/rappasoft/laravel-authentication-log/pull/94)

### 3.0.0 - 2023-02-23

Expand Down
5 changes: 5 additions & 0 deletions src/Listeners/FailedLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Auth\Events\Failed;
use Illuminate\Http\Request;
use Rappasoft\LaravelAuthenticationLog\Notifications\FailedLogin;
use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable;

class FailedLoginListener
{
Expand All @@ -18,11 +19,15 @@ public function __construct(Request $request)
public function handle($event): void
{
$listener = config('authentication-log.events.failed', Failed::class);

if (! $event instanceof $listener) {
return;
}

if ($event->user) {
if(! in_array(AuthenticationLoggable::class, class_uses_recursive(get_class($event->user)))){
return;
}

if (config('authentication-log.behind_cdn')) {
$ip = $this->request->server(config('authentication-log.behind_cdn.http_header_field'));
Expand Down
3 changes: 2 additions & 1 deletion src/Listeners/LoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public function __construct(Request $request)
public function handle($event): void
{
$listener = config('authentication-log.events.login', Login::class);

if (! $event instanceof $listener) {
return;
}

if ($event->user) {
if(!in_array(AuthenticationLoggable::class, class_uses_recursive(get_class($event->user))){
if(! in_array(AuthenticationLoggable::class, class_uses_recursive(get_class($event->user)))){
return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Listeners/LogoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Auth\Events\Logout;
use Illuminate\Http\Request;
use Rappasoft\LaravelAuthenticationLog\Models\AuthenticationLog;
use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable;

class LogoutListener
{
Expand All @@ -18,11 +19,16 @@ public function __construct(Request $request)
public function handle($event): void
{
$listener = config('authentication-log.events.logout', Logout::class);

if (! $event instanceof $listener) {
return;
}

if ($event->user) {
if(! in_array(AuthenticationLoggable::class, class_uses_recursive(get_class($event->user)))){
return;
}

$user = $event->user;

if (config('authentication-log.behind_cdn')) {
Expand Down
6 changes: 6 additions & 0 deletions src/Listeners/OtherDeviceLogoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Auth\Events\OtherDeviceLogout;
use Illuminate\Http\Request;
use Rappasoft\LaravelAuthenticationLog\Models\AuthenticationLog;
use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable;

class OtherDeviceLogoutListener
{
Expand All @@ -18,11 +19,16 @@ public function __construct(Request $request)
public function handle($event): void
{
$listener = config('authentication-log.events.other-device-logout', OtherDeviceLogout::class);

if (! $event instanceof $listener) {
return;
}

if ($event->user) {
if(! in_array(AuthenticationLoggable::class, class_uses_recursive(get_class($event->user)))){
return;
}

$user = $event->user;

if (config('authentication-log.behind_cdn')) {
Expand Down

0 comments on commit 0967d3a

Please sign in to comment.