From fd99821bd7ca047938482ebe1780f327ba2f8de6 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 30 Oct 2013 23:24:27 +0100 Subject: [PATCH] Logging in remembers original URL --- src/Bootstrap.php | 2 ++ src/Controllers/AuthController.php | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index f2a67b4e..69b4a1a2 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -61,5 +61,7 @@ class Bootstrap $this->context->viewName = 'error-exception'; (new \Chibi\View())->renderFile($this->context->layoutName); } + + AuthController::observeWorkFinish(); } } diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 50b8e96e..86c135bb 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -1,6 +1,17 @@ user = $dbUser; self::doReLog(); - \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); return $dbUser; } @@ -51,7 +61,7 @@ class AuthController //check if already logged in if ($this->context->loggedIn) { - \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); + self::redirectAfterLog(); return; } @@ -67,6 +77,7 @@ class AuthController setcookie('auth', TextHelper::encrypt($token), time() + 365 * 24 * 3600, '/'); } $this->context->transport->success = true; + self::redirectAfterLog(); } } @@ -107,7 +118,6 @@ class AuthController } } $context->user = unserialize($_SESSION['user']); - #throw new SimpleException($context->user->anonymous ? '1' : '0'); $context->loggedIn = $context->user->anonymous ? false : true; if (!$context->loggedIn) { @@ -128,4 +138,14 @@ class AuthController $_SESSION['user'] = serialize($context->user); self::doLogIn(); } + + public static function observeWorkFinish() + { + if (strpos(\Chibi\HeadersHelper::get('Content-Type'), 'text/html') === false) + return; + $context = \Chibi\Registry::getContext(); + if ($context->route->simpleControllerName == 'auth') + return; + $_SESSION['login-redirect-url'] = $context->query; + } }