你好我是cakephp的新手
我的问题是$this->Auth->login($this->request->data)
总是返回true,我不知道它是否与表名有关,我的表名是“admins”而不是“users”,它接受任何密码,有些东西是真的错了。
这是我的登录功能:
public function login()
{
$this->layout = 'login';
if ($this->request->is('post'))
{
if ($this->Auth->login())
{
return $this->redirect($this->Auth->redirect());
}
else
{
$this->Session->setFlash(__('Username or password is incorrect'));
}
}
}
我从here开始使用该功能,但这并非完全登录
我的旧代码是:
public function login()
{
$this->layout = 'login';
if(!$this->Session->read('Auth.User'))
{
debug($this->Session->read('Auth.User'));
if ($this->request->is('post'))
{
debug($this->Auth->login());
//$this->pa($this->request->data);
if ($this->Auth->login())
{
$this->Admin->id = $this->Session->read('Auth.Admin.id');
$this->redirect($this->Auth->redirect());
}
else
{
$this->Session->setFlash(__('Username or password is incorrect'));
}
}
}
else
{
return $this->redirect($this->Auth->redirect());
}
}
它也不起作用
答案 0 :(得分:0)
您需要更改Auth模型。将其添加到您的控制器并尝试。
function beforeFilter() {
$this->Auth->userModel = 'admins';
}
如果你有除用户名和密码以外的其他字段,你也需要将它们传递给Auth这样的东西
$this->Auth->fields = array(
'username' => 'your_username_field',
'password' => 'your_password_field'
);
希望这会有所帮助