diff --git a/app/Listeners/Authentication/FailedLoginListener.php b/app/Listeners/Authentication/FailedLoginListener.php index 45c6a591..ee483306 100644 --- a/app/Listeners/Authentication/FailedLoginListener.php +++ b/app/Listeners/Authentication/FailedLoginListener.php @@ -45,7 +45,9 @@ public function handle(mixed $event) : void * @var \App\Models\User */ $user = $event->user; - $ip = $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()); + $ip = config('2fauth.proxy_headers.forIp') + ? $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()) + : $this->request->ip(); $log = $user->authentications()->create([ 'ip_address' => $ip, diff --git a/app/Listeners/Authentication/LoginListener.php b/app/Listeners/Authentication/LoginListener.php index c8a56717..a3542389 100644 --- a/app/Listeners/Authentication/LoginListener.php +++ b/app/Listeners/Authentication/LoginListener.php @@ -43,8 +43,10 @@ public function handle(mixed $event) : void /** * @var \App\Models\User */ - $user = $event->user; - $ip = $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()); + $user = $event->user; + $ip = config('2fauth.proxy_headers.forIp') + ? $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()) + : $this->request->ip(); $userAgent = $this->request->userAgent(); $known = $user->authentications() ->whereIpAddress($ip) diff --git a/app/Listeners/Authentication/LogoutListener.php b/app/Listeners/Authentication/LogoutListener.php index 14fd5c4e..ccb66b36 100644 --- a/app/Listeners/Authentication/LogoutListener.php +++ b/app/Listeners/Authentication/LogoutListener.php @@ -42,8 +42,10 @@ public function handle(mixed $event) : void /** * @var \App\Models\User */ - $user = $event->user; - $ip = $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()); + $user = $event->user; + $ip = config('2fauth.proxy_headers.forIp') + ? $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()) + : $this->request->ip(); $userAgent = $this->request->userAgent(); $log = $user->authentications() ->whereIpAddress($ip) diff --git a/app/Listeners/Authentication/OtherDeviceLogoutListener.php b/app/Listeners/Authentication/OtherDeviceLogoutListener.php index 386cc2e4..d699b92e 100644 --- a/app/Listeners/Authentication/OtherDeviceLogoutListener.php +++ b/app/Listeners/Authentication/OtherDeviceLogoutListener.php @@ -48,8 +48,10 @@ public function handle(mixed $event) : void /** * @var \App\Models\User */ - $user = $event->user; - $ip = $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()); + $user = $event->user; + $ip = config('2fauth.proxy_headers.forIp') + ? $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()) + : $this->request->ip(); $userAgent = $this->request->userAgent(); $authLog = $user->authentications() ->whereIpAddress($ip) diff --git a/app/Listeners/Authentication/VisitedByProxyUserListener.php b/app/Listeners/Authentication/VisitedByProxyUserListener.php index 7e617224..8bfaa6e5 100644 --- a/app/Listeners/Authentication/VisitedByProxyUserListener.php +++ b/app/Listeners/Authentication/VisitedByProxyUserListener.php @@ -23,8 +23,10 @@ public function handle(mixed $event) : void /** * @var \App\Models\User */ - $user = $event->user; - $ip = $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()); + $user = $event->user; + $ip = config('2fauth.proxy_headers.forIp') + ? $this->request->header(config('2fauth.proxy_headers.forIp'), $this->request->ip()) + : $this->request->ip(); $userAgent = $this->request->userAgent(); $guard = config('auth.defaults.guard'); $known = $user->authentications()