user's authentification and cookies
Notice: This thread is very old.
- kekcuko
- Member | 5
Hello, I'm experiencing a trouble with setting cookies after user's login. It sets only this
- PHPSESSID kohainc22vetvi4e9cpve4fld5 domainname.com * in the session
But I was convinced that $user->setExpiration should have put some cookie for the user.
Here is a part from my login form :
public function validated($form) {
$values = $form->values;
try {
$user = $this->presenter->getUser();
if ($values->remember) {
$user->setExpiration(time() + 60*60*24*14, FALSE);
} else {
$user->setExpiration(time() + 60*20, TRUE);
}
$user->login($values->username, $values->password);
if ($user->isInRole('o'))
$this->presenter->redirect('o:p');
if ($user->isInRole('a'))
$this->presenter->redirect('a:d');
if ($user->isInRole('s'))
$this->presenter->redirect('t:');
} catch (Nette\Security\AuthenticationException $e) {
$form->addError($e->getMessage());
$this->presenter->redirect('Sign:in');
}
}
And authentificator:
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$row = User::find(array('username' => $username)); //phpactiverecord model
if (!$row) {
throw new NS\AuthenticationException("User not found", self::IDENTITY_NOT_FOUND);
}
if ($row->password !== self::calculateHash($password)) {
throw new NS\AuthenticationException("Incorrect pass", self::INVALID_CREDENTIAL);
}
if ($row->active == 0) {
throw new NS\AuthenticationException("Acc is blocked", self::INVALID_CREDENTIAL);
}
unset($row->password);
$identity = new NS\Identity($row->id, array('name'=> $row->roleName));
$identity->username = $row->username;
return $identity;
}
To sum up – the problem is that the cookies for authentificated user aren't set at all.
Thanks in advance!
- Patrik Votoček
- Member | 2221
you must setup global session expiration
Remember that the expiration time of a whole session (see Configuration session) has to be the same or greater than the time which was set for the separate sections or variables.