cakephp login never recognizes

2

I am studying CakePHP and I created a project to train login, but no matter what I do, login / password always denies access. here are the codes

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

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


    //---------------------------------
    $this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'fields' => [
                    'username' => 'email',
                    'password' => 'password'
                ]
            ]
        ],
        'loginAction' => [
            'controller' => 'Users',
            'action' => 'login'
        ],
         // If unauthorized, return them to page they were just on
        'unauthorizedRedirect' => $this->referer()
    ]);
    //------------------------------------

    $this->Auth->allow(['display', 'view', 'index']);
}

no longer users contoller

public function initialize()
{
    parent::initialize();
    // Add the 'add' action to the allowed actions list.
    $this->Auth->allow(['logout', 'add']);
}

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

    public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error('Your username or password is incorrect.');
    }
}

Already a login page:

{
  <h1>Login</h1>
  <?= $this->Form->create() ?>
  <?= $this->Form->control('email') ?>
  <?= $this->Form->control('password') ?>
  <?= $this->Form->button('Login') ?>
  <?= $this->Form->end() ?>
}

the bank table:

  CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    email VARCHAR(255) NOT NULL,
    password VARCHAR(255) NOT NULL,
    created DATETIME,
    modified DATETIME
  );

Anyway ... what's wrong? Thank you all !! Horacio

    
asked by anonymous 29.10.2017 / 00:48

1 answer

0

Friend tries the login action:

Tell me later if it worked.

public function login(){
    $this->layout = "login";
    if($this->request->is("post")){
        $dados = $this->request->data;
        if($this->Auth->login($dados)){
            $user = $this->User->Find("first", ["conditions" => ["User.username" => $dados["User"]["username"]  ] ]);
            $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Session->setFlash(__("Usuários ou senha incorretos!"), "default", array("class" => "danger"));
            $this->redirect("/users/login");
        }
    }

}

    
20.02.2018 / 21:48