You aren't defining the custom models you are using. By default Auth expects Users table not Usarios.
-- Read more here: http://book.cakephp.org/3.0/en/controllers/components/authentication.html#configuring-authentication-handlers
On Sunday, 22 February 2015 11:05:53 UTC-5, s.m.s...@gmail.com wrote:
On Sunday, 22 February 2015 11:05:53 UTC-5, s.m.s...@gmail.com wrote:
I'm new to CakePhp framework and followed the blog tutorial. Everything went smooth until authentication part.
This is my login method from UsersControllers.php, the debug line always returns false.
public function login() { if ($this->request->is('post')) { debug($this->Auth->identify())
; $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); return $this->redirect($this->Auth->redirectUrl ()); } $this->Flash->error(__('Usuario o contraseña inválida, intente nuevamente' )); } }This is my user class I had to change the line protected $_accessible = ['*' => true]; as appears in the tutorial, otherwise users wouldn't be saved.
class User extends Entity { // Make all fields mass assignable for now. protected $_accessible = ['username' => true,'password'=>true,'role'=>
true ,'created'=>true,'modified' =>true]; // ... protected function _setPassword($password) { return (new DefaultPasswordHasher)->hash($password ); } // ... }This is my login.ctp
<div class="users form"> <?= $this->Flash->render('auth') ?> <?= $this->Form->create() ?> <fieldset> <legend><?= __('Ingrese su usuario y contraseña') ?></legend> <?= $this->Form->input('Usuario') ?> <?= $this->Form->input('
Contraseña' ) ?> </fieldset> <?= $this->Form->button(__('Login')); ?> <?= $this->Form->end() ?> </div>These are my AppController.php methods:
public function initialize() { $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'loginRedirect' => [ 'controller' => 'Expedientes', 'action' => 'index' ], 'logoutRedirect' => [ 'controller' => 'Pages', 'action' => 'display', 'home' ] ]); } public function beforeFilter(Event $event) { $this->Auth->allow(['index', 'view']); }
At this point I can add users, their passwords are hashed but I can't login. Any help will be greatly appreciated. Thanks in advance.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment