Okay, update, im bit frustrated with the error, there’s the code what im trying to working with the login (im trying to test without password hashing)
AppController.php
class AppController extends Controller
{
/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading components.
*
* e.g. `$this->loadComponent('Security');`
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler', [
'enableBeforeRedirect' => false,
]);
$this->loadComponent('Flash');
//$this->loadComponent('Auth', [
// 'authenticate' => [
// 'Form' => [
// 'fields' => ['nombre' => 'nombre', 'contrasena' => 'contrasena']
// ]
// ],
// 'loginAction' => [
// 'controller' => 'persona',
// 'action' => 'login'
// ],
// 'authError' => 'Credenciales inválidos',
// 'loginRedirect' => '/persona/login',
// 'storage' => 'Session'
//]);
/*
* Enable the following component for recommended CakePHP security settings.
* see https://book.cakephp.org/3.0/en/controllers/components/security.html
*/
//$this->loadComponent('Security');
}
}
Entity of Persona
protected $_accessible = [
‘rut’ => true,
‘nombre’ => true,
‘apellido’ => true,
‘direccion’ => true,
‘telefono’ => true,
‘contrasena’ => true,
‘tipo_usuario_id’ => true,
‘tipo_usuario’ => true
];
protected $_hidden = [
'contrasena'
];
//protected function _setPassword($contrasena) {
// if(strlen($contrasena) > 0) {
// return (new DefaultPasswordHasher) -> hash($contrasena);
// }
//}
PersonaController.php
public function login() {
if ($this->request->is(‘post’)) {
$persona = $this->Auth->identify();
if ($persona) {
$this->Auth->setUser($persona);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(‘Tu nombre o password es incorrecto.’);
var_dump($persona);
}
}
public function logout() {
$this->Authentication->logout();
}
(At the end i didnt find out how to insert or put these codes, sorry)
Without the // the page of login needs to “where the USERS controller” not Persona controller, that was reason of being bit frustrated.
Any help is needed. Thanks.