0
私は次のコードを持っている:blog authenticationチュートリアルの間の唯一の本当の違い正直に言うとcakephp 3.xで投稿を使用しているときにログインに失敗しましたか?
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'
]
]);
}
と、これは次のとおりです。
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'));
}
}
をprint_r文とそれをjsonから配列に変更する入力行は、Auth-> identify()がCakeRequestで期待していると思います。私はケーキを使用しています3.2。
あなたはSRC /モデル/エンティティ/ User.php
で
use Cake\Auth\DefaultPasswordHasher;
パスワードの暗号化のためのコード
protected function _setPassword($password)
{
return (new DefaultPasswordHasher)->hash($password);
}
を逃したしますprint_rプリントアウト
Array
(
[username] => [email protected]
[password] => 1234
)
あなたは 'email'を渡すべきときに' username'を渡しました Alimonが言ったようにハッシュされたパスワードを持っていることを確認してください。 – JazzCat
@JazzCatあなたが書いたことは、それが働いたキー値を変更した後に正しいと言いました。 – jimmyjacks