yii\web\User::renewAuthStatus PHP Method

renewAuthStatus() protected method

This method will try to determine the user identity using the [[idParam]] session variable. If [[authTimeout]] is set, this method will refresh the timer. If the user identity cannot be determined by session, this method will try to [[loginByCookie()|login by cookie]] if [[enableAutoLogin]] is true.
protected renewAuthStatus ( )
    protected function renewAuthStatus()
    {
        $session = Yii::$app->getSession();
        $id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($this->idParam) : null;
        if ($id === null) {
            $identity = null;
        } else {
            /* @var $class IdentityInterface */
            $class = $this->identityClass;
            $identity = $class::findIdentity($id);
        }
        $this->setIdentity($identity);
        if ($identity !== null && ($this->authTimeout !== null || $this->absoluteAuthTimeout !== null)) {
            $expire = $this->authTimeout !== null ? $session->get($this->authTimeoutParam) : null;
            $expireAbsolute = $this->absoluteAuthTimeout !== null ? $session->get($this->absoluteAuthTimeoutParam) : null;
            if ($expire !== null && $expire < time() || $expireAbsolute !== null && $expireAbsolute < time()) {
                $this->logout(false);
            } elseif ($this->authTimeout !== null) {
                $session->set($this->authTimeoutParam, time() + $this->authTimeout);
            }
        }
        if ($this->enableAutoLogin) {
            if ($this->getIsGuest()) {
                $this->loginByCookie();
            } elseif ($this->autoRenewCookie) {
                $this->renewIdentityCookie();
            }
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Logout user if it's blocked
  */
 public function renewAuthStatus()
 {
     parent::renewAuthStatus();
     /* @var $identity User */
     if ($this->identity instanceof User && !$this->identity->canSignIn() && !$this->isGuest) {
         $this->logout();
     }
 }