Funciona: - Usuario - Empresa git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@2 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
84 lines
2.6 KiB
PHP
84 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Sirve para comprobar si un usuario en válido en el sistema a partir
|
|
* del email y de la contraseña.
|
|
*/
|
|
class IdentificacionUsuario extends CBaseUserIdentity {
|
|
|
|
private $_id;
|
|
public $email;
|
|
public $password;
|
|
|
|
// Constantes de error declaradas en la clase padre
|
|
//const ERROR_NONE=0;
|
|
//const ERROR_USERNAME_INVALID=1;
|
|
//const ERROR_PASSWORD_INVALID=2;
|
|
//const ERROR_UNKNOWN_IDENTITY=100;
|
|
|
|
const ERROR_ESTADO_NOACTIVO=3;
|
|
const ERROR_ESTADO_DENEGADO=4;
|
|
|
|
/**
|
|
* Contructor.
|
|
* @param string $email email
|
|
* @param string $password password
|
|
*/
|
|
public function __construct($email, $password) {
|
|
$this->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;
|
|
}
|
|
|
|
} |