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