From 3f279f358cda3902ebc6245357c83e31784173a0 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Tue, 2 Aug 2022 10:57:16 +0200 Subject: [PATCH] Add user logging after WebAuthn authentication - Fix #109 --- .../Controllers/Auth/WebAuthnLoginController.php | 16 ++++++++++++++++ app/Http/Middleware/LogUserLastSeen.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/WebAuthnLoginController.php b/app/Http/Controllers/Auth/WebAuthnLoginController.php index dc5750b7..92c0bace 100644 --- a/app/Http/Controllers/Auth/WebAuthnLoginController.php +++ b/app/Http/Controllers/Auth/WebAuthnLoginController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Http\Controllers\Controller; use DarkGhostHunter\Larapass\Http\AuthenticatesWebAuthn; +use Carbon\Carbon; class WebAuthnLoginController extends Controller { @@ -73,4 +74,19 @@ public function login(Request $request) return $this->traitLogin($request); } + + + /** + * The user has been authenticated. + * + * @param \Illuminate\Http\Request $request + * @param mixed $user + * + * @return void|\Illuminate\Http\JsonResponse + */ + protected function authenticated(Request $request, $user) + { + $user->last_seen_at = Carbon::now()->format('Y-m-d H:i:s'); + $user->save(); + } } \ No newline at end of file diff --git a/app/Http/Middleware/LogUserLastSeen.php b/app/Http/Middleware/LogUserLastSeen.php index 50d789d2..e971cc02 100644 --- a/app/Http/Middleware/LogUserLastSeen.php +++ b/app/Http/Middleware/LogUserLastSeen.php @@ -16,7 +16,7 @@ class LogUserLastSeen * @param string|null $guard * @return mixed */ - public function handle($request, Closure $next, ...$quards) + public function handle($request, Closure $next, ...$guards) { $guards = empty($guards) ? [null] : $guards;