From 23bc31d6e32488efa99566b978963cd84f6643e2 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Fri, 28 Oct 2016 14:58:39 +0200 Subject: [PATCH] Improved update of last login date (also include autoLogin) --- protected/humhub/config/web.php | 1 + protected/humhub/modules/user/components/Session.php | 2 +- protected/humhub/modules/user/components/User.php | 10 ++++++++++ .../humhub/modules/user/controllers/AuthController.php | 1 - 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/protected/humhub/config/web.php b/protected/humhub/config/web.php index 88b20d1cb6..f7c64627cc 100644 --- a/protected/humhub/config/web.php +++ b/protected/humhub/config/web.php @@ -13,6 +13,7 @@ $config = [ 'class' => 'humhub\modules\user\components\User', 'identityClass' => 'humhub\modules\user\models\User', 'enableAutoLogin' => true, + 'authTimeout' => 1400, 'loginUrl' => ['/user/auth/login'] ], 'errorHandler' => [ diff --git a/protected/humhub/modules/user/components/Session.php b/protected/humhub/modules/user/components/Session.php index 073ee4c37a..c435f46c8f 100644 --- a/protected/humhub/modules/user/components/Session.php +++ b/protected/humhub/modules/user/components/Session.php @@ -43,7 +43,7 @@ class Session extends DbSession // http://us.php.net/manual/en/function.session-set-save-handler.php try { $userId = new Expression('NULL'); - if (!Yii::$app->user->isGuest) { + if (!Yii::$app->user->getIsGuest()) { $userId = Yii::$app->user->id; } diff --git a/protected/humhub/modules/user/components/User.php b/protected/humhub/modules/user/components/User.php index e203c94858..da91cf56c3 100644 --- a/protected/humhub/modules/user/components/User.php +++ b/protected/humhub/modules/user/components/User.php @@ -126,4 +126,14 @@ class User extends \yii\web\User return null; } + /** + * @inheritdoc + */ + public function afterLogin($identity, $cookieBased, $duration) + { + $identity->updateAttributes(['last_login' => new \yii\db\Expression('NOW()')]); + + parent::afterLogin($identity, $cookieBased, $duration); + } + } diff --git a/protected/humhub/modules/user/controllers/AuthController.php b/protected/humhub/modules/user/controllers/AuthController.php index 91e46186c4..3af7c70738 100644 --- a/protected/humhub/modules/user/controllers/AuthController.php +++ b/protected/humhub/modules/user/controllers/AuthController.php @@ -175,7 +175,6 @@ class AuthController extends Controller AuthClientHelpers::updateUser($authClient, $user); if (Yii::$app->user->login($user, $duration)) { - $user->updateAttributes(['last_login' => new \yii\db\Expression('NOW()')]); Yii::$app->user->setCurrentAuthClient($authClient); $url = Yii::$app->user->returnUrl; }