en mi tabla de usuarios hay un campo en el cual se define si esta activo o inactivo alguien podría explicarme como hacer para que en el momento de login si esta persona se encuentra inactiva mediante un mensaje se le diga que no puede acceder por inactividad de su cuenta y que lo devuelva a la pagina de login
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity = new UserIdentity($this->username,$this->password);
$authErr = $this->_identity->authenticate();
$errStr = Yii::t('app', 'Usuario o contraseña incorrecta.');
switch ($authErr)
{
case UserIdentity::ERROR_NONE: break;
case UserIdentity::ERROR_PASSWORD_INVALID: break;
case UserIdentity::ERROR_USERNAME_INVALID: break;
case UserIdentity::ERROR_ACCOUNT_DISABLED:
$errStr = Yii::t('app', 'Cuenta inactiva - llame para ayuda.');
break;
}
if($authErr != UserIdentity::ERROR_NONE)
$this->addError('username', $errStr);
}
}
En UserIdentity.php:
const ERROR_ACCOUNT_DISABLED = 101;
...
/**
* Authenticates a user.
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = User::model()->findByAttributes(array('username'=>$this->username));
if(!is_object($user))
$user = User::model()->findByAttributes(array('email_address'=>$this->username));
if($user === NULL)
$this->errorCode = self::ERROR_UNKNOWN_IDENTITY; // not in users table
else if($user->is_active == false)
$this->errorCode = self::ERROR_ACCOUNT_DISABLED; // account has been disabled
else if (!CPasswordHelper::verifyPassword($this->password, $user->h_password))
$this->errorCode = self::ERROR_UNKNOWN_IDENTITY; // valid user but bad password
else // login success
{
$this->_id=$user->id;
$this->username=$user->username;
$this->errorCode = self::ERROR_NONE;
}
return $this->errorCode;
}