Browse Source

Added log messages to user login and logout actions.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
342a9a2e1a
  1. 8
      framework/yii/web/User.php

8
framework/yii/web/User.php

@ -180,6 +180,9 @@ class User extends Component
{ {
if ($this->beforeLogin($identity, false)) { if ($this->beforeLogin($identity, false)) {
$this->switchIdentity($identity, $duration); $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); $this->afterLogin($identity, false);
} }
return !$this->getIsGuest(); return !$this->getIsGuest();
@ -205,6 +208,8 @@ class User extends Component
if ($identity !== null && $identity->validateAuthKey($authKey)) { if ($identity !== null && $identity->validateAuthKey($authKey)) {
if ($this->beforeLogin($identity, true)) { if ($this->beforeLogin($identity, true)) {
$this->switchIdentity($identity, $this->autoRenewCookie ? $duration : 0); $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); $this->afterLogin($identity, true);
} }
} elseif ($identity !== null) { } elseif ($identity !== null) {
@ -225,6 +230,9 @@ class User extends Component
$identity = $this->getIdentity(); $identity = $this->getIdentity();
if ($identity !== null && $this->beforeLogout($identity)) { if ($identity !== null && $this->beforeLogout($identity)) {
$this->switchIdentity(null); $this->switchIdentity(null);
$id = $identity->getId();
$ip = Yii::$app->getRequest()->getUserIP();
Yii::info("User '$id' logged out from $ip.", __METHOD__);
if ($destroySession) { if ($destroySession) {
Yii::$app->getSession()->destroy(); Yii::$app->getSession()->destroy();
} }

Loading…
Cancel
Save