我有以下代码:
UserController中:
public function login()
{
if ($this->request->is('post')) {
$this->request->input('json_decode', true);
print_r($this->request->data);
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
在app控制器中我有:
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginaction' => [
'controller' => 'Users',
'action' => 'login'
]
]);
}
老实说,blog authentication教程与此之间唯一真正的区别是print_r语句和将其从json更改为数组的输入行,我认为这是Auth-> identify()所期望的在CakeRequest中。我正在使用蛋糕3.2。
print_r打印出来
Array
(
[username] => test1234@gmail.com
[password] => 1234
)
答案 0 :(得分:0)
你错过了
use Cake\Auth\DefaultPasswordHasher;
密码加密代码
protected function _setPassword($password)
{
return (new DefaultPasswordHasher)->hash($password);
}
在src / Model / Entity / User.php
中再次查看docs