diff --git a/app/Api/v1/Resources/UserAuthentication.php b/app/Api/v1/Resources/UserAuthentication.php index 522ba14f..2b29be83 100644 --- a/app/Api/v1/Resources/UserAuthentication.php +++ b/app/Api/v1/Resources/UserAuthentication.php @@ -51,7 +51,7 @@ public function __construct($resource) */ public function toArray($request) { - $tz = $request->user()->preferences['timezone']; + $tz = $request->user()?->preferences['timezone'] ?? config('app.timezone'); return [ 'id' => $this->id, diff --git a/app/Api/v1/Resources/UserManagerResource.php b/app/Api/v1/Resources/UserManagerResource.php index 8ccd5fd7..aa98eb40 100644 --- a/app/Api/v1/Resources/UserManagerResource.php +++ b/app/Api/v1/Resources/UserManagerResource.php @@ -85,7 +85,7 @@ protected function tokenExpired($createdAt) */ public function toArray($request) { - $tz = $request->user()?->preferences['timezone']; + $tz = $request->user()?->preferences['timezone'] ?? config('app.timezone'); return array_merge( parent::toArray($request), diff --git a/app/Http/Middleware/KickOutInactiveUser.php b/app/Http/Middleware/KickOutInactiveUser.php index 2d3f36d3..417b799d 100644 --- a/app/Http/Middleware/KickOutInactiveUser.php +++ b/app/Http/Middleware/KickOutInactiveUser.php @@ -29,7 +29,7 @@ public function handle($request, Closure $next, ...$guards) $user = Auth::user(); $now = Carbon::now(); - $inactiveFor = $now->diffInSeconds(Carbon::parse($user->last_seen_at)); + $inactiveFor = (int) $now->diffInSeconds(Carbon::parse($user->last_seen_at), true); // Fetch all setting values $kickUserAfterXSecond = intval($user->preferences['kickUserAfter']) * 60; diff --git a/app/Listeners/Authentication/LoginListener.php b/app/Listeners/Authentication/LoginListener.php index 3b60eb7a..8e67f364 100644 --- a/app/Listeners/Authentication/LoginListener.php +++ b/app/Listeners/Authentication/LoginListener.php @@ -46,7 +46,7 @@ public function handle(mixed $event) : void $ip = config('2fauth.proxy_headers.forIp') ?? $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; + $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; $guard = $event->guard; $log = $user->authentications()->create([ diff --git a/app/Listeners/Authentication/VisitedByProxyUserListener.php b/app/Listeners/Authentication/VisitedByProxyUserListener.php index 6bf3695e..b7b556eb 100644 --- a/app/Listeners/Authentication/VisitedByProxyUserListener.php +++ b/app/Listeners/Authentication/VisitedByProxyUserListener.php @@ -25,7 +25,7 @@ public function handle(mixed $event) : void $ip = config('2fauth.proxy_headers.forIp') ?? $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; + $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now(), true) < 1; $guard = config('auth.defaults.guard'); $log = $user->authentications()->create([ diff --git a/tests/Api/v1/Controllers/UserManagerControllerTest.php b/tests/Api/v1/Controllers/UserManagerControllerTest.php index e90330b2..1566c34c 100644 --- a/tests/Api/v1/Controllers/UserManagerControllerTest.php +++ b/tests/Api/v1/Controllers/UserManagerControllerTest.php @@ -138,8 +138,8 @@ public function test_show_returns_the_expected_UserManagerResource() : void 'preferences' => $this->defaultPreferences, 'is_admin' => false, 'twofaccounts_count' => 0, - 'last_seen_at' => '1 second ago', - 'created_at' => '1 second ago', + 'last_seen_at' => '0 seconds ago', + 'created_at' => '0 seconds ago', ], 'password_reset' => null, 'valid_personal_access_tokens' => 0,