蛋糕php 3.4登录不起作用?

时间:2017-06-17 03:47:44

标签: php mysql cakephp

  

appcontroller页面

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

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');

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

型号/实体/ user.php的

protected function _setPassword($password){
    return(new DefaultPasswordHasher)->Hash($password);
}
  

login.ctp

<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>
  

UsersController.php

public function login(){
    if($this->request->is('post'))
    {
        $user = $this->Auth->identify();
        if($user)
        {
            $this->Auth->setUser($user);
            return $this->redirect(['controller'=>'posts']);
        }
        else
        {
            $this->Flash->error('Incorrect Login Username and password in Tokyo');
        }
    }
}

即使输入正确的密码,也无法记录。问题是什么?我试图登录很长一段时间,但总是失败。

0 个答案:

没有答案