From a8a1d48f103c4cea92c814235498c4b498a597d6 Mon Sep 17 00:00:00 2001 From: Corne Oppelaar Date: Tue, 21 Jun 2016 02:11:40 +0200 Subject: [PATCH] save userId instead of full user --- src/Handler/Login/Action.php | 15 +++++++++++---- src/Handler/Logout.php | 2 +- src/Handler/Session.php | 10 +++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Handler/Login/Action.php b/src/Handler/Login/Action.php index 235f44d..00a0006 100644 --- a/src/Handler/Login/Action.php +++ b/src/Handler/Login/Action.php @@ -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'); } } \ No newline at end of file diff --git a/src/Handler/Logout.php b/src/Handler/Logout.php index 55a6224..728c3f1 100644 --- a/src/Handler/Logout.php +++ b/src/Handler/Logout.php @@ -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'); } diff --git a/src/Handler/Session.php b/src/Handler/Session.php index 4d01348..21d2018 100644 --- a/src/Handler/Session.php +++ b/src/Handler/Session.php @@ -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');