From 342a9a2e1a1e5d7468470e1ae6fc3b430276ecd8 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 11 Nov 2013 20:19:46 -0500 Subject: [PATCH] Added log messages to user login and logout actions. --- framework/yii/web/User.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/framework/yii/web/User.php b/framework/yii/web/User.php index eca2ed6..b77af2b 100644 --- a/framework/yii/web/User.php +++ b/framework/yii/web/User.php @@ -180,6 +180,9 @@ class User extends Component { if ($this->beforeLogin($identity, false)) { $this->switchIdentity($identity, $duration); + $id = $identity->getId(); + $ip = Yii::$app->getRequest()->getUserIP(); + Yii::info("User '$id' logged in from $ip.", __METHOD__); $this->afterLogin($identity, false); } return !$this->getIsGuest(); @@ -205,6 +208,8 @@ class User extends Component if ($identity !== null && $identity->validateAuthKey($authKey)) { if ($this->beforeLogin($identity, true)) { $this->switchIdentity($identity, $this->autoRenewCookie ? $duration : 0); + $ip = Yii::$app->getRequest()->getUserIP(); + Yii::info("User '$id' logged in from $ip via cookie.", __METHOD__); $this->afterLogin($identity, true); } } elseif ($identity !== null) { @@ -225,6 +230,9 @@ class User extends Component $identity = $this->getIdentity(); if ($identity !== null && $this->beforeLogout($identity)) { $this->switchIdentity(null); + $id = $identity->getId(); + $ip = Yii::$app->getRequest()->getUserIP(); + Yii::info("User '$id' logged out from $ip.", __METHOD__); if ($destroySession) { Yii::$app->getSession()->destroy(); }