在cakephp中登录不正确,即使一切都正确

时间:2019-06-04 11:07:09

标签: php cakephp

我是CakePHP的新手,它是一个了不起的PHP框架,我正在尝试构建一个新的应用程序 所以我进入登录页面的一部分,这是我尝试登录时的代码,提示“登录错误” 并且密码已散列

AppController

public function beforeFilter(Event $event) {
        $this->Auth->allow('display');
}

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

    $this->loadComponent('RequestHandler', [
        'enableBeforeRedirect' => false,
    ]);
    $this->loadComponent('Flash');
    $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => ' email',
                        'password' => 'password'
                    ]
                ]
            ],
            'loginAction' => [
                'controller' => 'user',
                'action' => 'login'
            ]
        ]);

    /*
     * Enable the following component for recommended CakePHP security settings.
     * see https://book.cakephp.org/3.0/en/controllers/components/security.html
     */
    //$this->loadComponent('Security');
}
}

// UserController

public function login(){
    if($this->request->is('post')){
        $user = $this->Auth->identify();
        if($user){
            $this->Auth->setUser($user);
            return $this->redirect(['controller' => 'reference']);
        }
        // Bad Login
        $this->Flash->error('Incorrect Login');
    }
}

// Logout
public function logout(){
     $this->Flash->success('You are logged out');
     return $this->redirect($this->Auth->logout());
}

// Login.ctp

<div class="users form">
<?= $this->Flash->render() ?>
<?= $this->Form->create() ?>
    <fieldset>
        <legend><?= __("Merci de rentrer vos nom d'utilisateur et mot de passe") ?></legend>
        <?= $this->Form->control('username') ?>
        <?= $this->Form->control('password') ?>
    </fieldset>
<?= $this->Form->button(__('Se Connecter')); ?>
<?= $this->Form->end() ?>
</div>

0 个答案:

没有答案