首先在UserIdentity.php里面将内容改为
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$username=strtolower($this->username);
$admin=Admins::model()->find('LOWER(username)=?',array($username));
if($admin===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$admin->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else {
$this->_id=$admin->id;
$this->username=$admin->username;
$this->setState('roles',$username->group);
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}
public function getId()
{
return $this->_id;
}
}
在model里面Admin.php
Admins这个类下面写
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function validatePassword($pwd)
{
return $this->hashPassword($pwd)===$this->pwd;
}
public function hashPassword($pwd)
{
return md5($pwd);
}