Exemplo n.º 1
0
 /**
  * Method for authenticating the administrators.
  */
 public function authenticate()
 {
     $user = Administrator::model()->findByAttributes(array('Username' => $this->username));
     $hashedKey = Administrator::hashPassword($this->password);
     if ($user === null) {
         // Such user was not found.
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif ($user->LoginKey !== $hashedKey) {
         // The password was not corret.
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         // Managed to log in!
         $this->_id = $user->Id;
         Yii::app()->user->id = $user->Id;
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }