From 5d8dadfaaef56c77c5590471299015f12bef7a28 Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Thu, 7 Mar 2024 18:47:00 +0100 Subject: [PATCH] Update last_login_at and last_login_ip on login via auth action --- CHANGELOG.md | 1 + src/User/Service/SocialNetworkAuthenticateService.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f922f62..033fa2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## dev +- Fix: Update last_login_at and last_login_ip on social networt authenticate (e.luhr) - Enh: Keycloak auth client (e.luhr) - Fix: Social Network Auth (eluhr) - Enh #532: /user/registration/register now shows form validation errors diff --git a/src/User/Service/SocialNetworkAuthenticateService.php b/src/User/Service/SocialNetworkAuthenticateService.php index c262684..dd604b8 100644 --- a/src/User/Service/SocialNetworkAuthenticateService.php +++ b/src/User/Service/SocialNetworkAuthenticateService.php @@ -74,9 +74,14 @@ class SocialNetworkAuthenticateService implements ServiceInterface Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Your account has been blocked.')); $this->authAction->setSuccessUrl(Url::to(['/user/security/login'])); } else { - Yii::$app->user->login($account->user, $this->controller->module->rememberLoginLifespan); - $this->authAction->setSuccessUrl(Yii::$app->getUser()->getReturnUrl()); - $result = true; + $result = Yii::$app->user->login($account->user, $this->controller->module->rememberLoginLifespan); + if ($result) { + $account->user->updateAttributes([ + 'last_login_at' => time(), + 'last_login_ip' => $this->controller->module->disableIpLogging ? '127.0.0.1' : Yii::$app->request->getUserIP(), + ]); + $this->authAction->setSuccessUrl(Yii::$app->getUser()->getReturnUrl()); + } } } else { $this->authAction->setSuccessUrl($account->getConnectionUrl());