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'); $session = $this->get('session');
$segment = $session->getSegment('main'); $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"); $segment->setFlash("error", "Login failed, username or password are incorrect");
return $this->redirect('/login'); 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'); return $this->redirect('/panel');
} }
} }

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

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

Loading…
Cancel
Save