I am making a login for a part of a website. Therefore I don’t want to start the Auth in the AppController but in the actual Controller I need it in.
In PremiumController:
[…]
use Cake\Controller\Component\AuthComponent;
[…]
public function initialize()
{
parent::initialize();$this->loadComponent('Auth', [ 'Basic' => ['userModel' => 'Clients'], 'Form' => ['userModel' => 'Clients'], 'loginAction' => [ 'controller' => 'Premium', 'action' => 'login', 'plugin' => false ], 'authError' => 'Unauthorized Access', 'authenticate' => [ 'Form' => [ 'fields' => [ 'username' => 'naam', 'password' => 'pass' ], 'userModel'=>'Clients', //Other table than Users 'passwordHasher' => [ 'className' => 'Premium', //use MD5 ] ] ], 'loginRedirect' => [ 'controller' => 'Premium', 'action' => 'dashboard' ], 'logoutRedirect' => [ 'controller' => 'Search', 'action' => 'index' ] ]);
}
[…] and lower the login part
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(__('Invalid username or password, try again'));
}
}
I don’t get any result from this. The $user remains ‘false’
How can I make this work and is there a way to proper debug the Auth component?