-1
我是CakePHP的新手,我看到了關於如何實現登錄視圖的tutorial on YouTube。CakePHP 3.3 - 身份驗證不起作用
我一直在按照教程,但$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');
}
}
在用戶模型中的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