我已经在 cakephp 3.2 中完成了登录的所有设置,但是在登录时它返回 false。
用户 Controller 中的登录函数
public function login() {
$this->viewBuilder()->layout('');
if ($this->request->is('post')) {
$user = $this->Auth->identify();
pj($user);//returning false
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
此函数 $user = $this->Auth->identify();
始终返回 false。
为什么我不能登录?
在数据库中密码存储为
$2y$10$4aD6Ye6YcmPGKgI/CmhJBO0E//9tV.KvhJIOFAhajyqt8vfxDVASC
我正在从 $this->request->data
获取电子邮件和密码。
任何建议将不胜感激。 提前谢谢你。
最佳答案
请像下面这样更改:-
首先在您的 Controller 中添加此代码(最好是 App Controller ):-
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'loginAction' => [
'controller' => 'Users',
'action' => 'login',
'plugin' => 'Users'
],
'authError' => 'Did you really think you are allowed to see that?',
'authenticate' => [
'Form' => [
'fields' => ['username' => 'email']
]
],
'storage' => 'Session'
]);
}
然后使用您的代码。它将正常工作。
关于php - $this->Auth->identify();在 cakephp 3.2 中返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35332297/