大家好,我已经尝试了基本的身份验证登录并且它工作正常,但是当与管理员前缀一起使用时
$this->Auth->login() is returning false.
这是我的代码片段,
在我添加的模型中,
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
在 AppController 我添加了以下代码,
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index', 'admin' => true),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login', 'admin' => true)
)
);
在 UsersController 我的管理员登录如下,
public function admin_login() {
if ($this->request->is('post')) {
//$this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']);
debug($this->request->data['User']['password']);
debug($this->Auth->login());
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
在上面,
debug($this->request->data['User']['password'])返回正确的密码,但
debug($this->Auth->login())返回 false。
我无法弄清楚它返回错误的原因是什么,是否需要对管理员路由进行任何更改。