Issue with DefaultPasswordHasher CakePHP



早上好

我有登录到我的web应用程序的问题。

当我在我的应用程序上注册没有错误(在我看来):

//Register
public function register() {
    $user = $this->Users->newEntity();
    if($this->request->is('post')) {
        $this->request->data('status', '0');
        $this->request->data('role', '0');
        $user = $this->Users->patchEntity($user, $this->request->data);
        if($this->Users->save($user)) {
            $this->Flash->success('You are registered and can login');
            return $this->redirect(['action' => 'login']);
        } else {
            $this->Flash->error('You are not registered');
        }
    }
    $this->set(compact('user'));
    $this->set('_serialize', ['user']);
}

当用户注册时我不能登录(我不知道为什么),但是如果我将登录其他用户并且我正在更改旧用户的密码->旧用户可以登录

我不知道问题的原因在哪里。

登录:

//Login
public function login() {
    if($this->request->is('post')) {
        $user = $this->Auth->identify();
        //dump($user);
        //die();
        if($user) {
            if($user['status'] == '1') {
                $this->Auth->setUser($user);
                return $this->redirect(['controller' => 'tasks']);
            }elseif($user['status'] == '0') {
                $this->Flash->error('You are not authorized to Log In. Please contact with Admin of Application');
            }
        } else {
            //Bad Login
            $this->Flash->error('Incorrect Login or Password');
        }
    }
}
有趣的是,当我写日志时,我写
dump($user);
die();

我收到"false"…

Login.ctp:

<div class="index large-4 medium-4 large-offset-4 medium-offset-4 columns">
<div class="panel">
    <center><?= $this->HTML->image('small_logo.png'); ?></center>
    <?= $this->Form->create(); ?>
        <?= $this->Form->input('email'); ?>
        <?= $this->Form->input('password'); ?>
        <center><?= $this->Form->submit('Log In', array('class' => 'button')); ?></center>
    <?= $this->Form->end(); ?>
</div>

我认为这个问题与'DefaultHasherPassword'有关,但我不知道问题在哪里,应该如何解决。请帮助。

这就像新用户不能登录,但当用户被修改(密码更改)-他可以登录

您可能会忘记添加字段username作为email(不确定,因为您没有共享您的代码)

$this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => [
                'username' => 'email', //email consider as username
                'password' => 'password'
            ]
        ]
    ],
    'loginAction' => [
        'controller' => 'Users',
        'action' => 'login'
    ]
]);

最新更新