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;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Administrator the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Administrator::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }