From b57e4903689f219653fff7cc788a997a48b56872 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 12 Feb 2023 21:02:23 +0100 Subject: [PATCH 01/18] use real user ip behind cloudflare --- src/Listeners/FailedLoginListener.php | 9 ++++++++- src/Listeners/LoginListener.php | 8 +++++++- src/Listeners/LogoutListener.php | 8 +++++++- src/Listeners/OtherDeviceLogoutListener.php | 8 +++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Listeners/FailedLoginListener.php b/src/Listeners/FailedLoginListener.php index 92c9e31..64c75b3 100644 --- a/src/Listeners/FailedLoginListener.php +++ b/src/Listeners/FailedLoginListener.php @@ -23,8 +23,15 @@ public function handle($event): void } if ($event->user) { + + if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { + $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + } else { + $ip = $this->request->ip(); + } + $log = $event->user->authentications()->create([ - 'ip_address' => $ip = $this->request->ip(), + 'ip_address' => $ip, 'user_agent' => $this->request->userAgent(), 'login_at' => now(), 'login_successful' => false, diff --git a/src/Listeners/LoginListener.php b/src/Listeners/LoginListener.php index 7c0eed5..9f29703 100644 --- a/src/Listeners/LoginListener.php +++ b/src/Listeners/LoginListener.php @@ -24,8 +24,14 @@ public function handle($event): void } if ($event->user) { + + if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { + $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + } else { + $ip = $this->request->ip(); + } + $user = $event->user; - $ip = $this->request->ip(); $userAgent = $this->request->userAgent(); $known = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->whereLoginSuccessful(true)->first(); $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now()) < 1; diff --git a/src/Listeners/LogoutListener.php b/src/Listeners/LogoutListener.php index 8f0d41a..3a5cf17 100644 --- a/src/Listeners/LogoutListener.php +++ b/src/Listeners/LogoutListener.php @@ -24,7 +24,13 @@ public function handle($event): void if ($event->user) { $user = $event->user; - $ip = $this->request->ip(); + + if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { + $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + } else { + $ip = $this->request->ip(); + } + $userAgent = $this->request->userAgent(); $log = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->orderByDesc('login_at')->first(); diff --git a/src/Listeners/OtherDeviceLogoutListener.php b/src/Listeners/OtherDeviceLogoutListener.php index 5b49868..49f076c 100644 --- a/src/Listeners/OtherDeviceLogoutListener.php +++ b/src/Listeners/OtherDeviceLogoutListener.php @@ -24,7 +24,13 @@ public function handle($event): void if ($event->user) { $user = $event->user; - $ip = $this->request->ip(); + + if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { + $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + } else { + $ip = $this->request->ip(); + } + $userAgent = $this->request->userAgent(); $authenticationLog = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first(); From a3761a22745ba1634ca83daa9da11ddf06806ebc Mon Sep 17 00:00:00 2001 From: Lucas Macedo Date: Tue, 28 Feb 2023 08:56:11 -0300 Subject: [PATCH 02/18] Create pt_BR.json --- resources/lang/pt_BR.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 resources/lang/pt_BR.json diff --git a/resources/lang/pt_BR.json b/resources/lang/pt_BR.json new file mode 100644 index 0000000..e621a8f --- /dev/null +++ b/resources/lang/pt_BR.json @@ -0,0 +1,14 @@ +{ + "A failed login to your account": "Um login com falha em sua conta", + "Account:": "Conta", + "Browser:": "Navegador:", + "If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.": "Se foi você, pode ignorar este alerta. Se você suspeitar de qualquer atividade suspeita em sua conta, altere sua senha.", + "IP Address:": "Endereço de IP:", + "Location:": "Localização:", + "Regards,": "Obrigado,", + "There has been a failed login attempt to your :app account.": "Houve uma falha na tentativa de login em seu :app conta.", + "Time:": "Data:", + "Unknown City": "Cidade Desconhecida", + "Unknown State": "Estado Desconhecido", + "Your :app account logged in from a new device.": "Sua :app foi acessada em um novo dispositivo" +} From 73747ee84ee51c85b0a0e358813623cfbba496dd Mon Sep 17 00:00:00 2001 From: Brett Bailey Date: Wed, 19 Apr 2023 09:04:30 +1000 Subject: [PATCH 03/18] Added PHPDocs to allow autocompletion in IDE --- src/Models/AuthenticationLog.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Models/AuthenticationLog.php b/src/Models/AuthenticationLog.php index 0ef1f85..d160369 100755 --- a/src/Models/AuthenticationLog.php +++ b/src/Models/AuthenticationLog.php @@ -5,6 +5,18 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; +/** + * @property int $id + * @property string $authenticatable_type + * @property int $authenticatable_id + * @property string|null $ip_address + * @property string|null $user_agent + * @property \Illuminate\Support\Carbon|null $login_at + * @property bool $login_successful + * @property \Illuminate\Support\Carbon|null $logout_at + * @property bool $cleared_by_user + * @property array|null $location + */ class AuthenticationLog extends Model { public $timestamps = false; From bad55077db665fac54e12d3923259075d4f3ccb6 Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 25 Apr 2023 09:34:41 +0200 Subject: [PATCH 04/18] config able abroch --- config/authentication-log.php | 11 +++++++++++ src/Listeners/LoginListener.php | 4 ++-- src/Listeners/LogoutListener.php | 4 ++-- src/Listeners/OtherDeviceLogoutListener.php | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/config/authentication-log.php b/config/authentication-log.php index 178e537..0826888 100644 --- a/config/authentication-log.php +++ b/config/authentication-log.php @@ -42,4 +42,15 @@ // When the clean-up command is run, delete old logs greater than `purge` days // Don't schedule the clean-up command if you want to keep logs forever. 'purge' => 365, + + // if you are behind an CDN proxy, set 'behind_cdn.http_header_field' to the corresponding http header field of your cdn + /* + + 'behind_cdn' => [ + 'http_header_field' => 'HTTP_CF_CONNECTING_IP' // used by Cloudflare + ], + + */ + + 'behind_cdn' => false, ]; diff --git a/src/Listeners/LoginListener.php b/src/Listeners/LoginListener.php index 9f29703..3973419 100644 --- a/src/Listeners/LoginListener.php +++ b/src/Listeners/LoginListener.php @@ -25,8 +25,8 @@ public function handle($event): void if ($event->user) { - if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { - $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + if (config('authentication-log.behind_cdn')) { + $ip = $this->request->server(config('authentication-log.behind_cdn.http_header_field')); } else { $ip = $this->request->ip(); } diff --git a/src/Listeners/LogoutListener.php b/src/Listeners/LogoutListener.php index 3a5cf17..980e30f 100644 --- a/src/Listeners/LogoutListener.php +++ b/src/Listeners/LogoutListener.php @@ -25,8 +25,8 @@ public function handle($event): void if ($event->user) { $user = $event->user; - if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { - $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + if (config('authentication-log.behind_cdn')) { + $ip = $this->request->server(config('authentication-log.behind_cdn.http_header_field')); } else { $ip = $this->request->ip(); } diff --git a/src/Listeners/OtherDeviceLogoutListener.php b/src/Listeners/OtherDeviceLogoutListener.php index fe25ffe..376a941 100644 --- a/src/Listeners/OtherDeviceLogoutListener.php +++ b/src/Listeners/OtherDeviceLogoutListener.php @@ -25,8 +25,8 @@ public function handle($event): void if ($event->user) { $user = $event->user; - if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { - $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + if (config('authentication-log.behind_cdn')) { + $ip = $this->request->server(config('authentication-log.behind_cdn.http_header_field')); } else { $ip = $this->request->ip(); } From 7c642ff2d46daab70c78e66f918902d8b39aa61b Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 25 Apr 2023 09:35:42 +0200 Subject: [PATCH 05/18] missed saving --- src/Listeners/FailedLoginListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Listeners/FailedLoginListener.php b/src/Listeners/FailedLoginListener.php index 64c75b3..ce30587 100644 --- a/src/Listeners/FailedLoginListener.php +++ b/src/Listeners/FailedLoginListener.php @@ -24,8 +24,8 @@ public function handle($event): void if ($event->user) { - if (!empty($this->request->server('HTTP_CF_CONNECTING_IP'))) { - $ip = $this->request->server('HTTP_CF_CONNECTING_IP'); + if (config('authentication-log.behind_cdn')) { + $ip = $this->request->server(config('authentication-log.behind_cdn.http_header_field')); } else { $ip = $this->request->ip(); } From 7c85a5e1256bf2bd44a8e6d7b205ea679db45c49 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 27 Apr 2023 08:57:16 +0200 Subject: [PATCH 06/18] added documentation --- config/authentication-log.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/authentication-log.php b/config/authentication-log.php index 0826888..8637882 100644 --- a/config/authentication-log.php +++ b/config/authentication-log.php @@ -43,14 +43,14 @@ // Don't schedule the clean-up command if you want to keep logs forever. 'purge' => 365, + // if you are behind an CDN proxy, set 'behind_cdn.http_header_field' to the corresponding http header field of your cdn + // for cloudflare u can have look at: https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/ /* - - 'behind_cdn' => [ - 'http_header_field' => 'HTTP_CF_CONNECTING_IP' // used by Cloudflare - ], - + 'behind_cdn' => [ + 'http_header_field' => 'HTTP_CF_CONNECTING_IP' // used by Cloudflare + ], */ - + // if you are not a cdn user, use false 'behind_cdn' => false, ]; From 09838ff2234b6d5fa3b8966a228f5b095b827cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20M=E1=BA=A1nh=20T=C3=B9ng?= <101539988+tungtm-unica@users.noreply.github.com> Date: Sun, 5 Nov 2023 22:26:49 +0700 Subject: [PATCH 07/18] add config listeners --- config/authentication-log.php | 7 +++++++ src/LaravelAuthenticationLogServiceProvider.php | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/authentication-log.php b/config/authentication-log.php index 178e537..7f340ae 100644 --- a/config/authentication-log.php +++ b/config/authentication-log.php @@ -16,6 +16,13 @@ 'logout-other-devices' => \Illuminate\Auth\Events\OtherDeviceLogout::class, ], + 'listeners' => [ + 'login' => \Rappasoft\LaravelAuthenticationLog\Listeners\LoginListener::class, + 'failed' => \Rappasoft\LaravelAuthenticationLog\Listeners\FailedLoginListener::class, + 'logout' => \Rappasoft\LaravelAuthenticationLog\Listeners\LogoutListener::class, + 'logout-other-devices' => \Rappasoft\LaravelAuthenticationLog\Listeners\OtherDeviceLogoutListener::class, + ], + 'notifications' => [ 'new-device' => [ // Send the NewDevice notification diff --git a/src/LaravelAuthenticationLogServiceProvider.php b/src/LaravelAuthenticationLogServiceProvider.php index 4fec13a..8081252 100644 --- a/src/LaravelAuthenticationLogServiceProvider.php +++ b/src/LaravelAuthenticationLogServiceProvider.php @@ -28,9 +28,9 @@ public function configurePackage(Package $package): void ->hasCommand(PurgeAuthenticationLogCommand::class); $events = $this->app->make(Dispatcher::class); - $events->listen(config('authentication-log.events.login', Login::class), LoginListener::class); - $events->listen(config('authentication-log.events.failed', Failed::class), FailedLoginListener::class); - $events->listen(config('authentication-log.events.logout', Logout::class), LogoutListener::class); - $events->listen(config('authentication-log.events.other-device-logout', OtherDeviceLogout::class), OtherDeviceLogoutListener::class); + $events->listen(config('authentication-log.events.login', Login::class), config('authentication-log.listeners.login', LoginListener::class)); + $events->listen(config('authentication-log.events.failed', Failed::class), config('authentication-log.listeners.failed', FailedLoginListener::class); + $events->listen(config('authentication-log.events.logout', Logout::class), config('authentication-log.listeners.logout', LogoutListener::class); + $events->listen(config('authentication-log.events.other-device-logout', OtherDeviceLogout::class), config('authentication-log.listeners.other-device-logout', OtherDeviceLogoutListener::class); } } From be5ddd8e76d282d063f8dbf48b32803caba7d016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20M=E1=BA=A1nh=20T=C3=B9ng?= <101539988+tungtm-unica@users.noreply.github.com> Date: Sun, 5 Nov 2023 16:27:23 +0000 Subject: [PATCH 08/18] Update LaravelAuthenticationLogServiceProvider.php --- src/LaravelAuthenticationLogServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LaravelAuthenticationLogServiceProvider.php b/src/LaravelAuthenticationLogServiceProvider.php index 8081252..73722fb 100644 --- a/src/LaravelAuthenticationLogServiceProvider.php +++ b/src/LaravelAuthenticationLogServiceProvider.php @@ -29,8 +29,8 @@ public function configurePackage(Package $package): void $events = $this->app->make(Dispatcher::class); $events->listen(config('authentication-log.events.login', Login::class), config('authentication-log.listeners.login', LoginListener::class)); - $events->listen(config('authentication-log.events.failed', Failed::class), config('authentication-log.listeners.failed', FailedLoginListener::class); - $events->listen(config('authentication-log.events.logout', Logout::class), config('authentication-log.listeners.logout', LogoutListener::class); - $events->listen(config('authentication-log.events.other-device-logout', OtherDeviceLogout::class), config('authentication-log.listeners.other-device-logout', OtherDeviceLogoutListener::class); + $events->listen(config('authentication-log.events.failed', Failed::class), config('authentication-log.listeners.failed', FailedLoginListener::class)); + $events->listen(config('authentication-log.events.logout', Logout::class), config('authentication-log.listeners.logout', LogoutListener::class)); + $events->listen(config('authentication-log.events.other-device-logout', OtherDeviceLogout::class), config('authentication-log.listeners.other-device-logout', OtherDeviceLogoutListener::class)); } } From 5efa752c649a8d53f9f56da43da3c710c94d17cd Mon Sep 17 00:00:00 2001 From: Mathieu maas <34303750+MathieuMaas@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:23:05 +0100 Subject: [PATCH 09/18] Fixes the down method for php artisan migrate:rollback --- database/migrations/create_authentication_log_table.php.stub | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/migrations/create_authentication_log_table.php.stub b/database/migrations/create_authentication_log_table.php.stub index 298e8b8..1b125e4 100644 --- a/database/migrations/create_authentication_log_table.php.stub +++ b/database/migrations/create_authentication_log_table.php.stub @@ -20,4 +20,9 @@ return new class extends Migration $table->json('location')->nullable(); }); } + + public function down(): void + { + Schema::dropIfExists(config('authentication-log.table_name')); + } }; From 1d009583800b74ab006bf463f5901c2282b10281 Mon Sep 17 00:00:00 2001 From: Mathieu maas <34303750+MathieuMaas@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:42:35 +0100 Subject: [PATCH 10/18] Update LoginListener.php --- src/Listeners/LoginListener.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Listeners/LoginListener.php b/src/Listeners/LoginListener.php index 7c0eed5..fa803ee 100644 --- a/src/Listeners/LoginListener.php +++ b/src/Listeners/LoginListener.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Carbon; use Rappasoft\LaravelAuthenticationLog\Notifications\NewDevice; +use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable; class LoginListener { @@ -24,6 +25,9 @@ public function handle($event): void } if ($event->user) { + if(!in_array(AuthenticationLoggable::class, class_uses_recursive(get_class($event->user))){ + return; + } $user = $event->user; $ip = $this->request->ip(); $userAgent = $this->request->userAgent(); From 4c9aa6c4f543d864b1839101a19fe1c4997992ca Mon Sep 17 00:00:00 2001 From: Adam Mazur <80200036+mazur-adam@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:55:22 +0100 Subject: [PATCH 11/18] laravel 11 support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9acf43a..8da7c74 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.1", - "illuminate/contracts": "^10.0", + "illuminate/contracts": "^10.0|^11.0", "spatie/laravel-package-tools": "^1.4.3" }, "require-dev": { From bdedfee70f9cd885d83e602f5a16655fab1e8a93 Mon Sep 17 00:00:00 2001 From: Anthony Rappa Date: Thu, 28 Mar 2024 20:36:10 -0400 Subject: [PATCH 12/18] Laravel 11 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6e481db..0ccff9d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ See the [documentation](https://rappasoft.com/docs/laravel-authentication-log) f 8.x | 1.x 9.x | 2.x 10.x | 3.x + 11.x | 4.x ## Installation From d30418f7951da77bbc0de93ebaf5dd8c6be1a6f1 Mon Sep 17 00:00:00 2001 From: rappasoft Date: Fri, 29 Mar 2024 00:42:07 +0000 Subject: [PATCH 13/18] Fix styling --- src/Listeners/LogoutListener.php | 2 +- src/Listeners/OtherDeviceLogoutListener.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Listeners/LogoutListener.php b/src/Listeners/LogoutListener.php index 980e30f..fdae93a 100644 --- a/src/Listeners/LogoutListener.php +++ b/src/Listeners/LogoutListener.php @@ -30,7 +30,7 @@ public function handle($event): void } else { $ip = $this->request->ip(); } - + $userAgent = $this->request->userAgent(); $log = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->orderByDesc('login_at')->first(); diff --git a/src/Listeners/OtherDeviceLogoutListener.php b/src/Listeners/OtherDeviceLogoutListener.php index 376a941..1711afa 100644 --- a/src/Listeners/OtherDeviceLogoutListener.php +++ b/src/Listeners/OtherDeviceLogoutListener.php @@ -24,7 +24,7 @@ public function handle($event): void if ($event->user) { $user = $event->user; - + if (config('authentication-log.behind_cdn')) { $ip = $this->request->server(config('authentication-log.behind_cdn.http_header_field')); } else { From 3692ab0257a20d18c12db4d8b0ad14907179e9ea Mon Sep 17 00:00:00 2001 From: Anthony Rappa Date: Thu, 28 Mar 2024 20:42:20 -0400 Subject: [PATCH 14/18] Add --- CHANGELOG.md | 6 ++++++ README.md | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e981d0..30c7c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `Laravel Authentication Log` will be documented in this file. +### 4.0.0 - 2024-03-28 + +- Laravel 11 Support (https://github.com/rappasoft/laravel-authentication-log/pull/100) +- Add config listeners +- Use real user IP behind Cloudflare + ### 3.0.0 - 2023-02-23 - Laravel 10 Support - https://github.com/rappasoft/laravel-authentication-log/pull/70 diff --git a/README.md b/README.md index 2c0ac2e..9c2ebd3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ ![Package Logo](https://banners.beyondco.de/Laravel%20Authentication%20Log.png?theme=dark&packageManager=composer+require&packageName=rappasoft%2Flaravel-authentication-log&pattern=hideout&style=style_1&description=Log+user+authentication+details+and+send+new+device+notifications.&md=1&showWatermark=0&fontSize=100px&images=lock-closed) [![Latest Version on Packagist](https://img.shields.io/packagist/v/rappasoft/laravel-authentication-log.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-authentication-log) -[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/rappasoft/laravel-authentication-log/run-tests?label=tests)](https://github.com/rappasoft/laravel-authentication-log/actions?query=workflow%3Arun-tests+branch%3Amain) -[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/rappasoft/laravel-authentication-log/Check%20&%20fix%20styling?label=code%20style)](https://github.com/rappasoft/laravel-authentication-log/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/rappasoft/laravel-authentication-log.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-authentication-log) ### Enjoying this package? [Buy me a beer 🍺](https://www.buymeacoffee.com/rappasoft) From dd4b45102fb5cb621a57c6e57d1d3a0a0fc3fc75 Mon Sep 17 00:00:00 2001 From: Anthony Rappa Date: Thu, 28 Mar 2024 20:44:51 -0400 Subject: [PATCH 15/18] Fix --- config/authentication-log.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/config/authentication-log.php b/config/authentication-log.php index 0b6ebb7..bcb0a4e 100644 --- a/config/authentication-log.php +++ b/config/authentication-log.php @@ -50,14 +50,12 @@ // Don't schedule the clean-up command if you want to keep logs forever. 'purge' => 365, + // If you are behind an CDN proxy, set 'behind_cdn.http_header_field' to the corresponding http header field of your cdn + // For cloudflare you can have look at: https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/ +// 'behind_cdn' => [ +// 'http_header_field' => 'HTTP_CF_CONNECTING_IP' // used by Cloudflare +// ], - // if you are behind an CDN proxy, set 'behind_cdn.http_header_field' to the corresponding http header field of your cdn - // for cloudflare u can have look at: https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/ - /* - 'behind_cdn' => [ - 'http_header_field' => 'HTTP_CF_CONNECTING_IP' // used by Cloudflare - ], - */ - // if you are not a cdn user, use false + // If you are not a cdn user, use false 'behind_cdn' => false, ]; From 0967d3a420f55b8f8fcd0162397c628bd85bdcc9 Mon Sep 17 00:00:00 2001 From: Anthony Rappa Date: Thu, 28 Mar 2024 20:54:24 -0400 Subject: [PATCH 16/18] Check for AuthenticationLoggable trait on event --- CHANGELOG.md | 3 ++- src/Listeners/FailedLoginListener.php | 5 +++++ src/Listeners/LoginListener.php | 3 ++- src/Listeners/LogoutListener.php | 6 ++++++ src/Listeners/OtherDeviceLogoutListener.php | 6 ++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30c7c1e..ae7753b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Listeners/FailedLoginListener.php b/src/Listeners/FailedLoginListener.php index ce30587..4d7981d 100644 --- a/src/Listeners/FailedLoginListener.php +++ b/src/Listeners/FailedLoginListener.php @@ -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 { @@ -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')); diff --git a/src/Listeners/LoginListener.php b/src/Listeners/LoginListener.php index c1c7971..aa58cc2 100644 --- a/src/Listeners/LoginListener.php +++ b/src/Listeners/LoginListener.php @@ -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; } diff --git a/src/Listeners/LogoutListener.php b/src/Listeners/LogoutListener.php index fdae93a..da3b9c6 100644 --- a/src/Listeners/LogoutListener.php +++ b/src/Listeners/LogoutListener.php @@ -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 { @@ -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')) { diff --git a/src/Listeners/OtherDeviceLogoutListener.php b/src/Listeners/OtherDeviceLogoutListener.php index 1711afa..d7766b9 100644 --- a/src/Listeners/OtherDeviceLogoutListener.php +++ b/src/Listeners/OtherDeviceLogoutListener.php @@ -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 { @@ -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')) { From 8ba15915d2b7609045b5e899e5a7a62d48d1088a Mon Sep 17 00:00:00 2001 From: rappasoft Date: Fri, 29 Mar 2024 00:54:43 +0000 Subject: [PATCH 17/18] Fix styling --- src/Listeners/FailedLoginListener.php | 2 +- src/Listeners/LoginListener.php | 2 +- src/Listeners/LogoutListener.php | 2 +- src/Listeners/OtherDeviceLogoutListener.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Listeners/FailedLoginListener.php b/src/Listeners/FailedLoginListener.php index 4d7981d..ab2effc 100644 --- a/src/Listeners/FailedLoginListener.php +++ b/src/Listeners/FailedLoginListener.php @@ -25,7 +25,7 @@ public function handle($event): void } 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; } diff --git a/src/Listeners/LoginListener.php b/src/Listeners/LoginListener.php index aa58cc2..185f338 100644 --- a/src/Listeners/LoginListener.php +++ b/src/Listeners/LoginListener.php @@ -26,7 +26,7 @@ public function handle($event): void } 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; } diff --git a/src/Listeners/LogoutListener.php b/src/Listeners/LogoutListener.php index da3b9c6..305b560 100644 --- a/src/Listeners/LogoutListener.php +++ b/src/Listeners/LogoutListener.php @@ -25,7 +25,7 @@ public function handle($event): void } 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; } diff --git a/src/Listeners/OtherDeviceLogoutListener.php b/src/Listeners/OtherDeviceLogoutListener.php index d7766b9..161f21b 100644 --- a/src/Listeners/OtherDeviceLogoutListener.php +++ b/src/Listeners/OtherDeviceLogoutListener.php @@ -25,7 +25,7 @@ public function handle($event): void } 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; } From b4548b4a71420841363b9de262581455244462d7 Mon Sep 17 00:00:00 2001 From: Anthony Rappa Date: Fri, 29 Mar 2024 21:04:23 -0400 Subject: [PATCH 18/18] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae7753b..6820e15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to `Laravel Authentication Log` will be documented in this f - 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) +- Added PHPDocs to allow autocompletion in IDE (https://github.com/rappasoft/laravel-authentication-log/pull/80) +- Fixes the down method for php artisan migrate:rollback (https://github.com/rappasoft/laravel-authentication-log/pull/93) ### 3.0.0 - 2023-02-23