首页 > 解决方案 > 在cakephp中登录不正确,即使一切都是正确的

问题描述

我是 CakePHP 的新手,这是一个了不起的 PHP 框架 我正在尝试构建一个新的应用程序,所以我进入了登录页面的一部分,这是我尝试登录时的代码

应用控制器

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');
}
}

//用户控制器

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());
}

//登录.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>

标签: phpcakephp

解决方案


推荐阅读