Skip to content

Commit

Permalink
Fixes issue pi-engine#42 for redirection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
taiwen committed May 2, 2013
1 parent 532d58c commit babb9ec
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
10 changes: 7 additions & 3 deletions usr/module/system/src/Controller/Front/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public function indexAction()

// Display login form
$form = $this->getForm();
$redirect = $this->params('redirect') ?: $this->request->getServer('HTTP_REFERER');
if ($redirect) {
$form->setData(array('redirect' => urlencode($redirect)));
$redirect = $this->params('redirect');
if (null === $redirect) {
$redirect = $this->request->getServer('HTTP_REFERER');
}
if (null !== $redirect) {
$redirect = $redirect ? urlencode($redirect) : '';
$form->setData(array('redirect' => $redirect));
}
$this->renderForm($form);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function indexAction()
{
$id = $this->params('id');
if (!$id) {
$this->redirect()->toRoute('user');
$this->redirect()->toRoute('user', array('controller' => 'account'));
return;
}
if (is_numeric($id)) {
Expand Down
6 changes: 6 additions & 0 deletions usr/module/system/src/Controller/Front/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function indexAction()
return;
}

// If already logged in
if (Pi::service('authentication')->hasIdentity()) {
$this->redirect()->toRoute('user', array('controller' => 'account'));
return;
}

// Display register form
$form = $this->getForm();
$this->renderForm($form);
Expand Down
9 changes: 7 additions & 2 deletions usr/module/system/src/Form/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ public function init()
'type' => 'csrf',
));

$redirect = Pi::engine()->application()->getRequest()->getServer('HTTP_REFERER') ?: Pi::engine()->application()->getRequest()->getRequestUri();
$request = Pi::engine()->application()->getRequest();
$redirect = $request->getQuery('redirect');
if (null === $redirect) {
$redirect = $request->getServer('HTTP_REFERER') ?: $request->getRequestUri();
}
$redirect = $redirect ? urlencode($redirect) : '';
$this->add(array(
'name' => 'redirect',
'type' => 'hidden',
'attributes' => array(
'value' => urlencode($redirect),
'value' => $redirect,
),
));

Expand Down
2 changes: 1 addition & 1 deletion www/setup/src/Controller/Finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function indexAction()
$readPaths .= "</ul>";

$message = <<<'HTML'
<h2>Congratulatons! The system is set up successfully. <a href='../index.php'>Click to visit your website!</a></h2>
<h2>Congratulatons! The system is set up successfully. <a href='../index.php?redirect=0'>Click to visit your website!</a></h2>
<h3>Security advisory</h3>
<ol>For security considerations please make sure the following operations are done:
<li>Remove the installation folder <strong>{www}/setup/</strong> from your server manually.</li>
Expand Down

0 comments on commit babb9ec

Please sign in to comment.