save userId instead of full user

master
Corne Oppelaar 9 years ago
parent ddc87ffeed
commit a8a1d48f10

@ -25,16 +25,23 @@ class Action extends Main
$session = $this->get('session');
$segment = $session->getSegment('main');
$user = $user->login($username, $password);
$loggedUser = $user->login($username, $password);
if ($user === null) {
if ($loggedUser === null) {
$segment->setFlash("error", "Login failed, username or password are incorrect");
return $this->redirect('/login');
}
$segment->set('user', $user);
$segment->set('userId', $loggedUser->getId());
$afterLogin = $segment->get('afterLogin');
$segment->set('afterLogin', null);
if ($afterLogin !== null) {
return $this->redirect($afterLogin);
}
return $this->redirect('/panel');
}
}

@ -17,7 +17,7 @@ class Logout extends Main
$session = $this->get('session');
$segment = $session->getSegment('main');
$segment->set('user', null);
$segment->set('userId', null);
return $this->redirect('/login');
}

@ -9,7 +9,7 @@
namespace Eater\Glim\Handler;
use Aura\Session\Segment;
use Eater\Glim\Model\Base\UserQuery;
use Eater\Glim\Model\UserQuery;
use Eater\Glim\Model\User;
use Eater\Glim\Service\TwigVars;
@ -18,7 +18,7 @@ class Session extends Main
/**
* @var bool
*/
protected $shouldHaveUser = false;
protected $shouldHaveUser = true;
/**
* @var bool
@ -60,12 +60,16 @@ class Session extends Main
/** @var Segment $segment */
$segment = $session->getSegment('main');
/** @var User $user */
$user = $segment->get('user');
$userId = $segment->get('userId');
$user = UserQuery::create()->findOneById($userId);
$twigVar->def('user', $user);
$this->setUser($user);
if ($user === null && ($this->shouldHaveUser || $this->shouldHaveSuperuser)) {
$segment->set('afterLogin', $this->getRequest()->getUri());
return $this->redirect('/login');
} elseif ($this->shouldHaveSuperuser && !$user->getSuperuser()) {
return $this->redirect('/panel');

Loading…
Cancel
Save