예제 #1
0
 /**
  * Logs in a user.
  *
  * The user identity information will be saved in storage that is
  * persistent during the user session. By default, the storage is simply
  * the session storage. If the duration parameter is greater than 0,
  * a cookie will be sent to prepare for cookie-based login in future.
  *
  * Note, you have to set {@link allowAutoLogin} to true
  * if you want to allow user to be authenticated based on the cookie information.
  *
  * @param IUserIdentity $identity the user identity (which should already be authenticated)
  * @param integer $duration number of seconds that the user can remain in logged-in status. Defaults to 0, meaning login till the user closes the browser.
  * If greater than 0, cookie-based login will be used. In this case, {@link allowAutoLogin}
  * must be set true, otherwise an exception will be thrown.
  * @return boolean whether the user is logged in
  */
 public function login($identity, $duration = 0)
 {
     $id = $identity->getId();
     $states = $identity->getPersistentStates();
     if ($this->beforeLogin($id, $states, false)) {
         $this->changeIdentity($id, $identity->getName(), $states);
         //      if($duration>0)
         //      {
         if ($this->allowAutoLogin) {
             $this->saveToCookie($duration);
         } else {
             throw new CException(Yii::t('yii', '{class}.allowAutoLogin must be set true in order to use cookie-based authentication.', array('{class}' => get_class($this))));
         }
         //      }
         $this->afterLogin(false);
     }
     return !$this->getIsGuest();
 }
예제 #2
0
 /**
  * Logs in a user.
  *
  * The user identity information will be saved in storage that is
  * persistent during the user session. By default, the storage is simply
  * the session storage. If the duration parameter is greater than 0,
  * a cookie will be sent to prepare for cookie-based login in future.
  *
  * Note, you have to set {@link allowAutoLogin} to true
  * if you want to allow user to be authenticated based on the cookie information.
  *
  * @param IUserIdentity $identity the user identity (which should already be authenticated)
  * @param integer $duration number of seconds that the user can remain in logged-in status. Defaults to 0, meaning login till the user closes the browser.
  * If greater than 0, cookie-based login will be used. In this case, {@link allowAutoLogin}
  * must be set true, otherwise an exception will be thrown.
  * @return boolean whether the user is logged in
  */
 public function login($identity, $duration = 0)
 {
     $id = $identity->getId();
     $states = $identity->getPersistentStates();
     if ($this->beforeLogin($id, $states, false)) {
         $this->changeIdentity($id, $identity->getName(), $states);
         if ($duration > 0) {
             if ($this->allowAutoLogin) {
                 $this->saveToCookie($duration);
             } else {
                 throw new CException(Yii::t('yii', '{class}.allowAutoLogin must be set true in order to use cookie-based authentication.', array('{class}' => get_class($this))));
             }
         }
         if ($this->absoluteAuthTimeout) {
             $this->setState(self::AUTH_ABSOLUTE_TIMEOUT_VAR, time() + $this->absoluteAuthTimeout);
         }
         $this->afterLogin(false);
     }
     return !$this->getIsGuest();
 }