Exemplo n.º 1
0
 public function authenticate()
 {
     $record = TblUser::model()->findByAttributes(array('name' => $this->username));
     //print_r($record);
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->password !== md5($this->password . $record->salt)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $record->uid;
             $this->setState('name', $record->name);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Exemplo n.º 2
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     /* $users=array(
     			// username => password
     			'demo'=>'demo',
     			'admin'=>'admin',
     		); */
     $record = TblUser::model()->findByAttributes(array('username' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->password !== $this->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Exemplo n.º 3
0
 /**
  * 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 TblUser the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = TblUser::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }