email = $email; $this->password = $password; } /** * Comprueba la identificación de un usuario * @return boolean whether authentication succeeds. */ public function authenticate() { $usuario = Usuario::model()->findByAttributes(array('email' => $this->email)); if ($usuario === NULL) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($usuario->password !== $usuario->encrypt($this->password)) $this->errorCode = self::ERROR_PASSWORD_INVALID; else if($usuario->estado == Usuario::ESTADO_NOACTIVO) $this->errorCode = self::ERROR_ESTADO_NOACTIVO; else if($usuario->estado == Usuario::ESTADO_DENEGADO) $this->errorCode = self::ERROR_ESTADO_DENEGADO; else { $this->_id = $usuario->id; $this->setState('id_empresa', $usuario->id_empresa); if ($usuario->last_login_time === null) { $lastLogin = time(); } else { $lastLogin = strtotime($usuario->last_login_time); $this->setState('lastLoginTime', $lastLogin); } $this->errorCode = self::ERROR_NONE; } } return !$this->errorCode; } /** * Returns the unique identifier for the identity. * The default implementation simply returns {@link username}. * This method is required by {@link IUserIdentity}. * @return string the unique identifier for the identity. */ public function getId() { return $this->_id; } /** * Returns the display name for the identity. * The default implementation simply returns {@link username}. * This method is required by {@link IUserIdentity}. * @return string the display name for the identity. */ public function getName() { return $this->email; } }