Я новичок в CakePHP, и я смотрел tutorial on YouTube о том, как реализовать вид входа.CakePHP 3.3 - Auth не работает
Я следовал за шагом, но $user
, кажется, никогда не будет правдой. Я получаю ошибку «Неверный вход», даже когда я пытаюсь войти с правильными учетными данными.
Где моя ошибка?
Войти функция UsersController.php
public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
/* never gets here ****************/
$this->Auth->setUser($user);
return $this->redirect(['controller' => 'posts']);
}
//Bad Login
$this->Flash->error('Incorrect Login');
}
}
инициализацией Auth в AppController
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
]
]);
Войти Форма
<br>
<div class="index large-4 medium-4 large-offset-4 medium-offset-4 columns">
<div class="panel">
<h2 class="text-center">
LOGIN
</h2>
<?= $this->Form->create(); ?>
<?= $this->Form->input('email'); ?>
<?= $this->Form->input('password', array('type' => 'password')); ?>
<?= $this->Form->submit('Login', array('class' => 'button')); ?>
<?= $this->Form->end(); ?>
</div>
</div>
_setPassword в модели пользователя
protected function _setPassword($password) {
return (new DefaultPasswordHasher)->hash($this->$password);
}
Вы уверены, что ваши пользователям зашифровать свой пароль? –
Да, все пароли хэшированы. Однако вы показали мне подходящее место для поиска. Благодаря! – mitch3ls