我又来了。
首先,用户登录验证这块之前已经是正确了的。包括了:1.正常登陆。2.密码错误。3.用户帐号已经被锁定。这三种情况的判断。但最近偶然输错密码,发现,密码错误后就出错了,显示空白页面。找了半天也找不出原因,也不确定是不是因为从1.02换成1.03造成的。我把几个代码贴一下,麻烦强帮我看看。(现在仅self::ERROR_USERNAME_INVALID报错正常,其他都会显示空白页面。)
UserIdentity.php:
<?php
public function authenticate()
{
$record=user::model()->findByAttributes(array('userlogin'=>$this->username));
if($record===null){
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if($record->userpassword!==md5($this->password))
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else if($record->userlock===1)
{
$this->errorCode=self::ERROR_USER_LOCKED;
}
else
{
$this->setState('usernum',$record->usernum);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
?>
LoginForm.php
<?php
if(!$this->hasErrors()) // we only want to authenticate when no input errors
{
$identity=new UserIdentity($this->username,$this->password);
$identity->authenticate();
switch($identity->errorCode)
{
case UserIdentity::ERROR_NONE:
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($identity,$duration);
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('username','用户名不存在.');
break;
case UserIdentity::ERROR_USER_LOCKED:
$this->addError('username','该账户已被冻结.');
break;
default: //UserIdentity::ERROR_PASSWORD_INVALID:
$this->addError('password','密码错误.');
break;
}
?>