public login ( yii\web\IdentityInterface $identity, integer $duration ) : boolean | ||
$identity | yii\web\IdentityInterface | the user identity (which should already be authenticated) |
$duration | integer | number of seconds that the user can remain in logged-in status, defaults to `0` |
return | boolean | whether the user is logged in |
public function login(IdentityInterface $identity, $duration = 0)
{
if ($this->beforeLogin($identity, false, $duration)) {
$this->switchIdentity($identity, $duration);
$id = $identity->getId();
$ip = Yii::$app->getRequest()->getUserIP();
if ($this->enableSession) {
$log = "User '{$id}' logged in from {$ip} with duration {$duration}.";
} else {
$log = "User '{$id}' logged in from {$ip}. Session not enabled.";
}
Yii::info($log, __METHOD__);
$this->afterLogin($identity, false, $duration);
}
return !$this->getIsGuest();
}
public function login(IdentityInterface $identity, $duration = null) { return parent::login($identity, isset($duration) ? $duration : $this->loginDuration); }