0
I’m having problems with the cake authorization component, I’ve done several tests and it’s the only component that isn’t working, I’ve checked the bank authorization, and I have authorization normally, I’ve reinstalled my system from 0 and do new design but the problem remains, I have already checked the values of my password and username fields and are correct, I have already tested with the encrypted and unencrypted password and nothing either.
I’ve been trying to solve the problem for weeks and I can’t find any solution on the Internet or in the documentation that can help me. The only solution and I think you can have, in my view, is to force a request in the model to do the authorization without using the native component, but I’m not being able to use the cake query itself to do this. Follows my code
Appcontroller
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\Core\Configure;
class AppController extends Controller
{
public function initialize()
{
/*parent::initialize();
$this->loadComponent('RequestHandler', [
'enableBeforeRedirect' => false,
]);*/
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'username',
'password' => 'password'
]
]
],
'loginRedirect' => [
'controller' => 'Pagprincipal',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pagprincipal',
'action' => 'login'
]
]);
}
public function beforeFilter(Event $event)
{
$this->Auth->allow(['index', 'view']);
}
}
Usercontroller
namespace App\Controller;
use App\Controller\AppController;
class UsersController extends AppController
{
public function login()
{
if($this->request->is('post')){
$user = $this->Auth->identify();
if('Users'){
$this->Auth->setUser('Users');
return $this->redirect($this->Auth->redirectUrl());
}else{
$this->Flash->error(__('Username ou senha inválidos, tente novamente!'));
}
}
}
Login.ctp
<div>
<?= $this->Flash->render('auth') ?>
<?= $this->Form->create() ?>
<div>
<form>
<?php
echo $this->Form->control('username');
echo $this->Form->control('password');
?>
<p>
<input type="checkbox" name="remember" id="remember" <?php if(isset($_COOKIE["member_login"])) { ?> checked <?php } ?> />
<label for="remember-me">Lembrar</label>
</p>
</form>
<button>Entrar</button>
</div>
</div>