From a180d8ac086462b6287f99284f6d2c123236445c Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Fri, 9 May 2014 11:41:34 +0100 Subject: [PATCH] Making login redirect you to where you were trying to go after logging in. --- PHPCI/Application.php | 1 + PHPCI/Controller/SessionController.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index ecc71ad5..5d1d9f9d 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -51,6 +51,7 @@ class Application extends b8\Application $response->setResponseCode(401); $response->setContent(''); } else { + $_SESSION['login_redirect'] = substr($request->getPath(), 1); $response = new RedirectResponse($response); $response->setHeader('Location', PHPCI_URL.'session/login'); } diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index def6d4c4..48a70475 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -43,7 +43,7 @@ class SessionController extends \PHPCI\Controller if ($user && password_verify($this->getParam('password', ''), $user->getHash())) { $_SESSION['user_id'] = $user->getId(); - header('Location: ' . PHPCI_URL); + header('Location: ' . $this->getLoginRedirect()); die; } else { $isLoginFailure = true; @@ -159,4 +159,16 @@ MSG; return $this->view->render(); } + + protected function getLoginRedirect() + { + $rtn = PHPCI_URL; + + if (!empty($_SESSION['login_redirect'])) { + $rtn .= $_SESSION['login_redirect']; + $_SESSION['login_redirect'] = null; + } + + return $rtn; + } }