我在登录与使用 AuthController 的用户不同的模型时遇到问题。
它是管理员,而不是用户表。
在我的管理员模型中,我有:
function beforeSave(){
if(isset($this->data['Administrator']['password']))
$this->data['Administrator']['password'] = AuthController::password($this->data['Administrator']['password']);
return true;
}
应用控制器:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array('controller' => 'administrators', 'action' => 'login'),
'loginRedirect' => array('controller' => 'Home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'Home', 'action' => 'index'),
'authError' => "You can't access that page.",
'authorize' => array('Controller')
)
);
public function beforeFilter(){
$this->Auth->userModel = 'Administrator';
}
在管理员控制器中:
public function login(){
if($this->request->is('post')){
if($this->Auth->login()){
$this->redirect($this->Auth->redirect());
}
else{
$this->Session->setFlash('Your username/password combination was incorrect.');
}
}
}
public function logout(){
$this->redirect($this->Auth->logout());
}
public function beforeFilter(){
parent::beforeFilter();
}
并查看:
<?php
echo $this->Form->create('Administrator', array('controller' => 'administrators', 'action' => 'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
我调试了 $this->request->data['Administrator']['password'] 并且我得到了与数据库中相同的哈希值。
我不知道为什么它总是说用户名/密码不正确。