Merge pull-request #274 (url redirection/session expired)

This commit is contained in:
Frédéric Guillot
2014-09-19 20:45:40 +02:00
4 changed files with 23 additions and 3 deletions

View File

@@ -124,7 +124,7 @@ abstract class Base
// Authentication // Authentication
if (! $this->authentication->isAuthenticated($controller, $action)) { 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 // 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'); $this->response->redirect('?controller=app');
} }
$redirect_query = $this->request->getStringParam('redirect_query');
$this->response->html($this->template->layout('user_login', array( $this->response->html($this->template->layout('user_login', array(
'errors' => array(), 'errors' => array(),
'values' => array(), 'values' => array(),
'no_layout' => true, 'no_layout' => true,
'redirect_query' => $redirect_query,
'title' => t('Login') 'title' => t('Login')
))); )));
} }
@@ -49,17 +51,23 @@ class User extends Base
*/ */
public function check() public function check()
{ {
$redirect_query = $this->request->getStringParam('redirect_query');
$values = $this->request->getValues(); $values = $this->request->getValues();
list($valid, $errors) = $this->authentication->validateForm($values); list($valid, $errors) = $this->authentication->validateForm($values);
if ($valid) { 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( $this->response->html($this->template->layout('user_login', array(
'errors' => $errors, 'errors' => $errors,
'values' => $values, 'values' => $values,
'no_layout' => true, 'no_layout' => true,
'redirect_query' => $redirect_query,
'title' => t('Login') 'title' => t('Login')
))); )));
} }

View File

@@ -136,4 +136,16 @@ class Request
$name = 'HTTP_'.str_replace('-', '_', strtoupper($name)); $name = 'HTTP_'.str_replace('-', '_', strtoupper($name));
return isset($_SERVER[$name]) ? $_SERVER[$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'];
}
} }

View File

@@ -8,7 +8,7 @@
<p class="alert alert-error"><?= Helper\escape($errors['login']) ?></p> <p class="alert alert-error"><?= Helper\escape($errors['login']) ?></p>
<?php endif ?> <?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() ?> <?= Helper\form_csrf() ?>