/**
  * Autentica un usuario
  * Verfica si usuario existe en base de datos
  * y que corresponda con su password
  * @return boolean si autenticacion es correcta
  */
 public function authenticate()
 {
     $user = Operador::model()->find(array('condition' => 't.usuario=:usuario', 'params' => array(':usuario' => $this->username)));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->activo != Yii::app()->params->usuario['estado']['activo']) {
             $this->errorCode = self::ERROR_USER_INACTIVE;
         } else {
             if (!$user->validarContrasena($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->errorCode = self::ERROR_NONE;
                 $this->user = $user;
             }
         }
     }
     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 Operador the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Operador::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'La página solicitada no existe.');
     }
     return $model;
 }