/**
  * 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()
 {
     $username = strtolower($this->username);
     $user = UserDefn::model()->find('username=?', array($username));
     if ($user == null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->validatePassword($this->password)) {
             $this->errorCode = self::ERROR_NONE;
         } else {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         }
     }
     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 UserDefn the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = UserDefn::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }