summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Controller/Base.php2
-rw-r--r--app/Controller/User.php10
-rw-r--r--app/Core/Request.php12
-rw-r--r--app/Templates/user_login.php2
4 files changed, 23 insertions, 3 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 1ef54d8e..93749ea6 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -124,7 +124,7 @@ abstract class Base
// Authentication
if (! $this->authentication->isAuthenticated($controller, $action)) {
- $this->response->redirect('?controller=user&action=login');
+ $this->response->redirect('?controller=user&action=login&redirect_query='.urlencode($this->request->getQueryString()));
}
// Check if the user is allowed to see this page
diff --git a/app/Controller/User.php b/app/Controller/User.php
index a02dd7be..72ef521c 100644
--- a/app/Controller/User.php
+++ b/app/Controller/User.php
@@ -34,10 +34,12 @@ class User extends Base
$this->response->redirect('?controller=app');
}
+ $redirect_query = $this->request->getStringParam('redirect_query');
$this->response->html($this->template->layout('user_login', array(
'errors' => array(),
'values' => array(),
'no_layout' => true,
+ 'redirect_query' => $redirect_query,
'title' => t('Login')
)));
}
@@ -49,17 +51,23 @@ class User extends Base
*/
public function check()
{
+ $redirect_query = $this->request->getStringParam('redirect_query');
$values = $this->request->getValues();
list($valid, $errors) = $this->authentication->validateForm($values);
if ($valid) {
- $this->response->redirect('?controller=board');
+ if ($redirect_query != "") {
+ $this->response->redirect('?'.$redirect_query);
+ } else {
+ $this->response->redirect('?controller=board');
+ }
}
$this->response->html($this->template->layout('user_login', array(
'errors' => $errors,
'values' => $values,
'no_layout' => true,
+ 'redirect_query' => $redirect_query,
'title' => t('Login')
)));
}
diff --git a/app/Core/Request.php b/app/Core/Request.php
index a1513459..e86cf609 100644
--- a/app/Core/Request.php
+++ b/app/Core/Request.php
@@ -136,4 +136,16 @@ class Request
$name = 'HTTP_'.str_replace('-', '_', strtoupper($name));
return isset($_SERVER[$name]) ? $_SERVER[$name] : '';
}
+
+ /**
+ * Returns current request's query string, useful for redirecting
+ *
+ * @access public
+ * @return string
+ */
+ public function getQueryString()
+ {
+ return $_SERVER['QUERY_STRING'];
+ }
+
}
diff --git a/app/Templates/user_login.php b/app/Templates/user_login.php
index 9eb4fa17..cf92cd4d 100644
--- a/app/Templates/user_login.php
+++ b/app/Templates/user_login.php
@@ -8,7 +8,7 @@
<p class="alert alert-error"><?= Helper\escape($errors['login']) ?></p>
<?php endif ?>
- <form method="post" action="?controller=user&amp;action=check">
+ <form method="post" action="?controller=user&amp;action=check&amp;redirect_query=<?= urlencode($redirect_query) ?>">
<?= Helper\form_csrf() ?>