From 4f17e2aff0078986788e00e4c15ebc4cb7979eca Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:34:29 +0200 Subject: [PATCH] Fix format of log entries without login date --- app/Api/v1/Resources/UserAuthentication.php | 7 +++++- resources/js/components/AccessLogViewer.vue | 27 +++++++++++++++++---- resources/lang/en/admin.php | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/Api/v1/Resources/UserAuthentication.php b/app/Api/v1/Resources/UserAuthentication.php index 926730d0..65585551 100644 --- a/app/Api/v1/Resources/UserAuthentication.php +++ b/app/Api/v1/Resources/UserAuthentication.php @@ -53,7 +53,12 @@ public function toArray($request) 'browser' => $this->agent->browser(), 'platform' => $this->agent->platform(), 'device' => $this->agent->deviceType(), - 'login_at' => Carbon::parse($this->login_at)->toDayDateTimeString(), + 'login_at' => $this->login_at + ? Carbon::parse($this->login_at)->toDayDateTimeString() + : null, + 'logout_at' => $this->logout_at + ? Carbon::parse($this->logout_at)->toDayDateTimeString() + : null, 'login_successful' => $this->login_successful, 'duration' => $this->logout_at ? Carbon::parse($this->logout_at)->diffForHumans(Carbon::parse($this->login_at), ['syntax' => CarbonInterface::DIFF_ABSOLUTE]) diff --git a/resources/js/components/AccessLogViewer.vue b/resources/js/components/AccessLogViewer.vue index 3ef151df..71cffea3 100644 --- a/resources/js/components/AccessLogViewer.vue +++ b/resources/js/components/AccessLogViewer.vue @@ -58,6 +58,18 @@ return 'display' } } + + const isSuccessfulLogin = (authentication) => { + return authentication.login_successful && authentication.login_at + } + + const isSuccessfulLogout = (authentication) => { + return !authentication.login_at && authentication.logout_at + } + + const isFailedEntry = (authentication) => { + return !authentication.login_successful && !authentication.logout_at + }