Hi there,
i programming a new website with version 3.8.1 and at the beginning war everything fine. I had added the login and was working good. After some updates on my code and adding some new sites, the login doesnt work anymore. I can create a new account, but dont login.
I think, the system open no session.
With print_r I get only the number 1:
login
public function login()
{
if ($this->request->is(‘post’)) {
print_r($this->request->is(‘post’));
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect(['controller' => 'charactersheet', 'action' => 'index']);
#return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}
}
userstable
public function validationDefault(Validator $validator)
{
$validator
->nonNegativeInteger(‘id’)
->allowEmptyString(‘id’, null, ‘create’);
$validator
->scalar('username')
->maxLength('username', 256)
->allowEmptyString('username');
$validator
->scalar('password')
->maxLength('password', 256)
->allowEmptyString('password');
$validator
->email('email')
->allowEmptyString('email');
$validator
->scalar('sprache')
->maxLength('sprache', 3)
->allowEmptyString('sprache');
$validator
->date('geburtstag')
->allowEmptyDate('geburtstag');
$validator
->nonNegativeInteger('mod')
->allowEmptyString('mod', 0, 'create');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->isUnique(['email']));
return $rules;
}
user
protected $_accessible = [
‘username’ => true,
‘password’ => true,
‘email’ => true,
‘sprache’ => true,
‘geburtstag’ => true,
‘mod’ => true
];
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var array
*/
protected $_hidden = [
'password'
];
protected function _setPassword($value)
{
if (strlen($value)) {
$hasher = new DefaultPasswordHasher();
return $hasher->hash($value);
}
}
appcontroller
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler', [
'enableBeforeRedirect' => false,
]);
$this->loadComponent('Flash');
/*
* Enable the following component for recommended CakePHP security settings.
* see https://book.cakephp.org/3.0/en/controllers/components/security.html
*/
#$this->loadComponent('Security');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'email' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
// If unauthorized, return them to page they were just on
'unauthorizedRedirect' => $this->referer()
]);
// Allow the display action so our PagesController
// continues to work. Also enable the read only actions.
$this->Auth->allow(['display', 'login', 'impressum', 'datenschutz', 'aboutus', 'kontakt', 'home']);
}
what have I done wrong?
Thanks for your help