redirect to original target page after logging in

This commit is contained in:
Lim Yuen Hoe
2014-09-19 01:38:38 +08:00
parent 7fac9783c6
commit ed13a04c4c
4 changed files with 23 additions and 3 deletions

View File

@@ -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

View File

@@ -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')
)));
}