首页 > 解决方案 > cakephp $this- auth- identify() 返回 false

问题描述

请我真的需要帮助我在论坛上尝试了几乎所有东西

方法 $this->Auth->identify(); 总是返回假

数据库中密码的长度是 varchar(255)

我的 cakephp 版本是 3.6.8

候选控制器

public function login()
{
    if ($this->request->is('post')) 
    {
        $candidat = $this->Auth->identify(); 
        if ($candidat) 
        {
            $this->Auth->setUser($candidat);
            return $this->redirect(['Controller'=>'Candidat','action'=>'index']);
        }
     $this->Flash->error(__('The candidat could not be saved Please try again.'));
    }
}

应用控制器

public function initialize()
{
    parent::initialize();

    $this->loadComponent('RequestHandler', [
        'enableBeforeRedirect' => false,
    ]);
    $this->loadComponent('Flash');
    $this->loadComponent('Auth', [
    'authError' => 'Vous croyez vraiment que vous pouvez faire cela?',
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'email','password' => 'password']
        ]
    ],
    'loginAction' => [
        'controller' => 'candidat',
        'action' => 'login',
    ],
    'storage' => 'Session'
    ]);

}

登录

<?= $this->Form->create() ?>
<fieldset>
    <legend><?= __('login') ?></legend>
    <?php
        echo $this->Form->control('Email_cand',['label'=>'Email']);
        echo $this->Form->control('password',['label'=>'mot de passe']);
    ?>
</fieldset>
<?= $this->Form->button(__('connecter')) ?>
<?= $this->Form->end() ?>

标签: cakephp

解决方案


推荐阅读