Reputation: 65
I have a login problem. New user registration works, password is encrypted, but I can not login. My login action is in the UsersAcces plugin and I think this is a problem. What's wrong?
Config Auth in src/AppController:
$this->loadComponent('Auth', [
'loginAction' => [
'controller' => 'Users',
'action' => 'login',
'plugin' => 'UsersAcces'
],
'loginRedirect' => [
'plugin' => 'UsersAcces',
'controller' => 'Users',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login',
'plugin' => 'UsersAcces'
],
'authError' => 'Brak dostępu!',
'authenticate' => [
'Form' => [
'fields' => ['username' => 'username','password'=>'password'],
'userModel'=>'UsersAcces.Users',
'relatedModel' => ['UsersAcces.Roles', 'UsersAcces.Addresses', 'UsersAcces.Emails', 'UsersAcces.Permissions', 'UsersAcces.Telephones'],//'UsersAcces.Roles',
'finder' => 'auth'
]
],
'storage' => 'Session',
'autoRedirect' => false
]);
Action login i plugins/UsersAcces/src/Controller/Users:
public function login(){
$this->viewBuilder()->setLayout("login");
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
return $this->redirect($this->Auth->redirectUrl());
}else{
$this->Flash->error(__('Niewłaściwy login lub hasło. Spróbuj ponownie.'));
}
}
//$user = $this->Users->newEntity();
$this->set(compact("user"));
}
Function findAuth in plugins/UsersAcces/src/Model/Table/UsersTable:
public function findAuth(\Cake\ORM\Query $query, array $options)
{
$query
->select()
->where(['Users._delete' => 0]);
return $query;
}
Function setPassword in plugins/UsersAcces/src/Model/Entity/User:
protected function _setPassword($password)
{
if (strlen($password) > 0) {
return (new DefaultPasswordHasher)->hash($password);
}
}
Please help.
Upvotes: 0
Views: 214
Reputation: 65
I found a solution! I did not add a line to file "plugins/UsersAcces/src/Controller/Users":
$this->Auth->setUser($user);
Upvotes: 1
Reputation: 23
You need to add the password Hasher under the 'Form' key in your Auth component initialization params, like:
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Default'
)
),
Upvotes: 0