大家好:
根据手册,我把authenticate写成下面这样,但是在登录时,是不是还要写一些额外的sql语句?否则默认的密码和用户名是什么。
public function authenticate()
{
/*$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);*/
$username = strtolower($this->username);
$user = User::model()->find('LOWER(username)=?',array($username));
if($user === null)
{
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if(!$user->validatePassword($this->password))
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else
{
$this->_id = $user->id;
$this->username = $user->username;
$this->errorCode = self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
/*
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
*/
}