Skip to content

Commit

Permalink
Correctly redirect to the last page visited in the login module (see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 26, 2019
1 parent 59629d6 commit bbc83b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
9 changes: 1 addition & 8 deletions src/Resources/contao/controllers/BackendMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ protected function output()
$this->Template->manager = (strpos($objSession->get('filePickerRef'), 'contao/page?') !== false) ? $GLOBALS['TL_LANG']['MSC']['pagePickerHome'] : $GLOBALS['TL_LANG']['MSC']['filePickerHome'];
}

$referer = null;

if ($request = $container->get('request_stack')->getCurrentRequest())
{
$referer = base64_encode($request->getQueryString());
}

$this->Template->theme = Backend::getTheme();
$this->Template->base = Environment::get('base');
$this->Template->language = $GLOBALS['TL_LANGUAGE'];
Expand All @@ -250,7 +243,7 @@ protected function output()
$this->Template->preview = $GLOBALS['TL_LANG']['MSC']['fePreview'];
$this->Template->previewTitle = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['fePreviewTitle']);
$this->Template->profile = $GLOBALS['TL_LANG']['MSC']['profile'];
$this->Template->referer = $referer;
$this->Template->referer = base64_encode(Environment::get('queryString'));
$this->Template->profileTitle = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['profileTitle']);
$this->Template->security = $GLOBALS['TL_LANG']['MSC']['security'];
$this->Template->logout = $GLOBALS['TL_LANG']['MSC']['logoutBT'];
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/contao/modules/ModuleLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public function generate()
return $objTemplate->parse();
}

if (!$_POST && $this->redirectBack && ($strReferer = $this->getReferer()) != Environment::get('request'))
if ($_POST)
{
$this->targetPath = $strReferer;
$this->targetPath = (string) Input::post('_target_path');
}
else
elseif ($this->redirectBack && ($referer = Input::get('referer', true)))
{
$this->targetPath = (string) Input::post('_target_path');
$this->targetPath = Environment::get('base') . base64_decode($referer, true);
}

return parent::generate();
Expand Down
5 changes: 4 additions & 1 deletion src/Resources/contao/pages/PageError401.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ protected function prepare($objRootPage=null)
throw new ForwardPageNotFoundException('Forward page not found');
}

$this->redirect($objNextPage->getFrontendUrl(), (($obj401->redirect == 'temporary') ? 302 : 301));
// Add the referer so the login module can redirect back
$referer = base64_encode(Environment::get('request'));

$this->redirect($objNextPage->getFrontendUrl() . '?referer=' . $referer, (($obj401->redirect == 'temporary') ? 302 : 301));
}

return $obj401;
Expand Down

0 comments on commit bbc83b2

Please sign in to comment.