ActionController: JS should redirect to __SELF__...

...once you lost your session. That's the only way to do this in a
smooth way. When the server get's an unauthenticated request for a
single container, redirecting to auth/login?redir=<that-container>
was not what you expect.

Together with JS handling __SELF__ in redirection URLs this will
play fine.

refs #6935
This commit is contained in:
Thomas Gelf 2014-08-19 09:54:24 +02:00
parent b9cc964e24
commit 9d4a4f49c9

View File

@ -256,8 +256,20 @@ class ActionController extends Zend_Controller_Action
*/ */
protected function redirectToLogin($afterLogin = '/dashboard') protected function redirectToLogin($afterLogin = '/dashboard')
{ {
if (! $afterLogin instanceof Url) {
$afterLogin = Url::fromPath($afterLogin);
}
if ($this->isXhr()) {
$redir = '__SELF__';
} else {
// TODO: Ignore /?
$redir = $afterLogin->getRelativeUrl();
}
$url = Url::fromPath('authentication/login'); $url = Url::fromPath('authentication/login');
$url->setParam('redirect', $afterLogin); if ($redir) {
$url->setParam('redirect', $redir);
}
$this->rerenderLayout()->redirectNow($url); $this->rerenderLayout()->redirectNow($url);
} }
@ -273,18 +285,12 @@ class ActionController extends Zend_Controller_Action
return $this->getRequest()->isXmlHttpRequest(); return $this->getRequest()->isXmlHttpRequest();
} }
/** protected function redirectXhr($url)
* Redirect to a specific url, updating the browsers URL field
*
* @param Url|string $url The target to redirect to
**/
public function redirectNow($url)
{ {
if (! $url instanceof Url) { if (! $url instanceof Url) {
$url = Url::fromPath($url); $url = Url::fromPath($url);
} }
$url = preg_replace('~&amp;~', '&', $url);
if ($this->isXhr()) {
if ($this->rerenderLayout) { if ($this->rerenderLayout) {
$this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes'); $this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes');
} }
@ -293,13 +299,27 @@ class ActionController extends Zend_Controller_Action
} }
$this->getResponse() $this->getResponse()
->setHeader('X-Icinga-Redirect', rawurlencode($url)) ->setHeader('X-Icinga-Redirect', rawurlencode($url->getAbsoluteUrl()))
->sendHeaders(); ->sendHeaders();
// TODO: Session shutdown? // TODO: Session shutdown?
exit; exit;
}
/**
* Redirect to a specific url, updating the browsers URL field
*
* @param Url|string $url The target to redirect to
**/
public function redirectNow($url)
{
if ($this->isXhr()) {
$this->redirectXhr($url);
} else { } else {
$this->_helper->Redirector->gotoUrlAndExit(Url::fromPath($url)->getRelativeUrl()); if (! $url instanceof Url) {
$url = Url::fromPath($url);
}
$this->_helper->Redirector->gotoUrlAndExit($url->getRelativeUrl());
} }
} }