After logging in a user:
- the user's identity information is obtainable from the [[identity]] property
If [[enableSession]] is true:
- the identity information will be stored in session and be available in the next requests
- in case of $duration == 0: as long as the session remains active or till the user closes the browser
- in case of $duration > 0: as long as the session remains active or as long as the cookie
remains valid by it's $duration in seconds when [[enableAutoLogin]] is set true.
If [[enableSession]] is false:
- the $duration parameter will be ignored
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 = null) { return parent::login($identity, isset($duration) ? $duration : $this->loginDuration); }
public function login(IdentityInterface $identity, $duration = 0) { $this->_identity = $identity; return parent::login($identity, $duration); }
/** * @inheritdoc */ public function login(IdentityInterface $identity, $duration = 0) { if (parent::login($identity, $duration)) { /** @var User $identity */ $identity->last_login_ip = ip2long(Yii::$app->request->userIP); $identity->last_login_at = time(); return true; } else { return false; } }
public function login(IdentityInterface $identity, $duration = 0) { return parent::login($identity, $duration); }