diff --git a/app/Api/v1/Controllers/UserManagerController.php b/app/Api/v1/Controllers/UserManagerController.php index 37a63ccc..5ed63cef 100644 --- a/app/Api/v1/Controllers/UserManagerController.php +++ b/app/Api/v1/Controllers/UserManagerController.php @@ -216,10 +216,12 @@ public function authentications(Request $request, User $user) $this->authorize('view', $user); $validated = $this->validate($request, [ + 'period' => 'sometimes|numeric', 'limit' => 'sometimes|numeric', ]); - $authentications = $request->has('limit') ? $user->authentications->take($validated['limit']) : $user->authentications; + $authentications = $request->has('period') ? $user->authentications($validated['period'])->get() : $user->authentications->get(); + $authentications = $request->has('limit') ? $authentications->take($validated['limit']) : $authentications; return UserAuthentication::collection($authentications); } diff --git a/app/Models/Traits/AuthenticationLoggable.php b/app/Models/Traits/AuthenticationLoggable.php new file mode 100644 index 00000000..df347b30 --- /dev/null +++ b/app/Models/Traits/AuthenticationLoggable.php @@ -0,0 +1,22 @@ +subMonths($period); + + return $this->morphMany(AuthenticationLog::class, 'authenticatable') + ->where('login_at', '>=', $from) + ->orWhere('logout_at', '>=', $from) + ->orderByDesc('id'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 45cee0f1..6ae8655f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Traits\AuthenticationLoggable; use App\Models\Traits\WebAuthnManageCredentials; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Auth\Notifications\ResetPassword; @@ -12,7 +13,6 @@ use Illuminate\Support\Str; use Laragear\WebAuthn\WebAuthnAuthentication; use Laravel\Passport\HasApiTokens; -use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable; /** * App\Models\User diff --git a/resources/js/components/AccessLogViewer.vue b/resources/js/components/AccessLogViewer.vue index 71cffea3..3b8ca54a 100644 --- a/resources/js/components/AccessLogViewer.vue +++ b/resources/js/components/AccessLogViewer.vue @@ -1,7 +1,8 @@