0
我想在我的登录添加新的自定义错误,如果user_status是“0”,那么它应该给的错误,我出发如下:加入的错误代码
UserIdentity.php
const ERROR_USERNAME_INACTIVE=68;
public function authenticate()
{
$user = Users::model()->findByAttributes(array('email'=>$this->username));
if ($user===null)
{
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if ($user->password !== md5($this->password))
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else if($user->user_status !='1')
{
$this->errorCode=self::ERROR_USERNAME_INACTIVE;
}
else
{
$this->errorCode=self::ERROR_NONE;
$this->_id = $user->id;
}
return !$this->errorCode;
}
在login.php中
case UserIdentity::ERROR_NONE:
Yii::app()->user->login($identity);
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('username','No Such user is associated with us .');
break;
case UserIdentity::ERROR_USERNAME_INACTIVE:
$this->addError('user_status','Sorry, this user is not activated yet');
default: // UserIdentity::ERROR_PASSWORD_INVALID
$this->addError('password','Password is incorrect.');
break;
现在我得到的问题,当user_Status是!= 1,那么它是正确给错误,但也给人,密码不正确,而密码是正确
thanx @topher .. –