From 0c3192d7743d0158f9fb539e3949d384c91b8013 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Thu, 3 Feb 2011 13:44:12 +0200 Subject: [PATCH] Implement redirection support for logins --- controllers/authentication.php | 17 ++++++++++++++++- templates/midgardmvc-login-form.xhtml | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/controllers/authentication.php b/controllers/authentication.php index 5b663e0..fc31245 100644 --- a/controllers/authentication.php +++ b/controllers/authentication.php @@ -26,9 +26,19 @@ public function get_logout(array $args) public function get_login(array $args) { + if (!isset($this->data['redirect_url'])) + { + $this->data['redirect_url'] = '/'; + + if (isset($_GET['redirect'])) + { + $this->data['redirect_url'] = $_GET['redirect']; + } + } + if (midgardmvc_core::get_instance()->authentication->is_user()) { - midgardmvc_core::get_instance()->head->relocate('/'); + midgardmvc_core::get_instance()->head->relocate($this->data['redirect_url']); } $exception_data = array(); @@ -41,6 +51,11 @@ public function get_login(array $args) public function post_login(array $args) { + if (isset($_POST['redirect'])) + { + $this->data['redirect_url'] = $_POST['redirect']; + } + if ( isset($_POST['username']) && isset($_POST['password'])) { diff --git a/templates/midgardmvc-login-form.xhtml b/templates/midgardmvc-login-form.xhtml index 77f2d77..327d020 100644 --- a/templates/midgardmvc-login-form.xhtml +++ b/templates/midgardmvc-login-form.xhtml @@ -19,6 +19,7 @@
Lorem ipsum
+