I'm trying to login with POST and Auth however unsuccessfully returning FALSE the function "$ this-> Auth-> identify ()" within my UsersController
Here are my settings from AppController to view
AppController
public function initialize() {
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth');
$this->loadComponent('Cookie');
}
function beforeFilter(Event $event) {
$this->Auth->allow('add');
$this->Auth->config('authorize','Controller',true);
$this->Auth->config('authenticate', ['Form' => ['fields' => ['username' => 'username', 'password' => 'password']]]);
$this->Auth->config('logoutRedirect', 'Homes/index',true);
$this->Auth->config('loginRedirect', 'Homes/index',true);
$this->Auth->config('loginAction', 'Users/login',true);
$this->Auth->config('loginError', 'Usuário e/ou senha incorreto(s)',true);
$this->Auth->config('authError', 'Você precisa fazer login para acessar esta página',true);
$this->Auth->config('userModel', 'Users',true);
}
UsersController
public function login() {
if ($this->request->is('post')) {
/* Here return FALSE */
if ($this->Auth->identify()) {
$this->Session->setFlash(__('Welcome, ' . $this->Auth->user('username')));
} else {
$this->Auth->flash('Login errado');
}
}
}
login.ctp
<?= $this->Form->create(); ?>
<?php // $this->Form->create('Users'); ?>
<fieldset>
<legend><?= __('Login') ?></legend>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?= $this->Form->button(__('Login')) ?>
<?= $this->Form->end() ?>
table mysql username and password varchar 200