params/_render: replace it everywhere
Cleaning up controllers and JS, using headers only and respecting history.
This commit is contained in:
parent
aded901aa5
commit
23ed744747
|
@ -65,16 +65,12 @@ class AuthenticationController extends ActionController
|
||||||
$this->view->title = $this->translate('Icingaweb Login');
|
$this->view->title = $this->translate('Icingaweb Login');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$redirectUrl = Url::fromPath($this->_request->getParam('redirect', 'dashboard'));
|
$redirectUrl = Url::fromPath($this->params->get('redirect', 'dashboard'));
|
||||||
|
|
||||||
if ($this->_request->isXmlHttpRequest()) {
|
|
||||||
$redirectUrl->setParam('_render', 'layout');
|
|
||||||
}
|
|
||||||
|
|
||||||
$auth = AuthManager::getInstance();
|
$auth = AuthManager::getInstance();
|
||||||
|
|
||||||
if ($auth->isAuthenticated()) {
|
if ($auth->isAuthenticated()) {
|
||||||
$this->redirectNow($redirectUrl);
|
$this->rerenderLayout()->redirectNow($redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -99,7 +95,7 @@ class AuthenticationController extends ActionController
|
||||||
$authenticated = $backend->authenticate($user);
|
$authenticated = $backend->authenticate($user);
|
||||||
if ($authenticated === true) {
|
if ($authenticated === true) {
|
||||||
$auth->setAuthenticated($user);
|
$auth->setAuthenticated($user);
|
||||||
$this->redirectNow($redirectUrl);
|
$this->rerenderLayout()->redirectNow($redirectUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +119,7 @@ class AuthenticationController extends ActionController
|
||||||
}
|
}
|
||||||
if ($authenticated === true) {
|
if ($authenticated === true) {
|
||||||
$auth->setAuthenticated($user);
|
$auth->setAuthenticated($user);
|
||||||
$this->redirectNow($redirectUrl);
|
$this->rerenderLayout()->redirectNow($redirectUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($backendsWithError === $backendsTried) {
|
if ($backendsWithError === $backendsTried) {
|
||||||
|
@ -161,8 +157,7 @@ class AuthenticationController extends ActionController
|
||||||
$this->_helper->layout->setLayout('login');
|
$this->_helper->layout->setLayout('login');
|
||||||
$this->_response->setHttpResponseCode(401);
|
$this->_response->setHttpResponseCode(401);
|
||||||
} else {
|
} else {
|
||||||
$this->_helper->layout->setLayout('inline');
|
$this->rerenderLayout()->redirectToLogin();
|
||||||
$this->redirectToLogin();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,11 +192,7 @@ class ConfigController extends BaseConfigController
|
||||||
$manager->enableModule($module);
|
$manager->enableModule($module);
|
||||||
$manager->loadModule($module);
|
$manager->loadModule($module);
|
||||||
Notification::success('Module "' . $module . '" enabled');
|
Notification::success('Module "' . $module . '" enabled');
|
||||||
$this->redirectNow(Url::fromPath('config/modules', array(
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
||||||
'_render' => 'layout',
|
|
||||||
'_reload' => 'css'
|
|
||||||
)));
|
|
||||||
return;
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->view->exceptionMesssage = $e->getMessage();
|
$this->view->exceptionMesssage = $e->getMessage();
|
||||||
$this->view->moduleName = $module;
|
$this->view->moduleName = $module;
|
||||||
|
@ -215,11 +211,7 @@ class ConfigController extends BaseConfigController
|
||||||
try {
|
try {
|
||||||
$manager->disableModule($module);
|
$manager->disableModule($module);
|
||||||
Notification::success('Module "' . $module . '" disabled');
|
Notification::success('Module "' . $module . '" disabled');
|
||||||
$this->redirectNow(Url::fromPath('config/modules', array(
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
||||||
'_render' => 'layout',
|
|
||||||
'_reload' => 'css'
|
|
||||||
)));
|
|
||||||
return;
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->view->exceptionMessage = $e->getMessage();
|
$this->view->exceptionMessage = $e->getMessage();
|
||||||
$this->view->moduleName = $module;
|
$this->view->moduleName = $module;
|
||||||
|
|
|
@ -45,12 +45,7 @@ class IndexController extends ActionController
|
||||||
public function preDispatch()
|
public function preDispatch()
|
||||||
{
|
{
|
||||||
if ($this->getRequest()->getActionName() !== 'welcome') {
|
if ($this->getRequest()->getActionName() !== 'welcome') {
|
||||||
$url = Url::fromPath('dashboard');
|
$this->redirectNow('dashboard');
|
||||||
$render = $this->_request->getParam('_render');
|
|
||||||
if ($render) {
|
|
||||||
$url->setParam('_render', $render);
|
|
||||||
}
|
|
||||||
$this->redirectNow($url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ if (! $this->auth()->isAuthenticated()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current url
|
// Current url
|
||||||
$url = Url::fromRequest()->remove('_render')->getRelativeUrl();
|
$url = Url::fromRequest()->getRelativeUrl();
|
||||||
$menu = Menu::fromConfig();
|
$menu = Menu::fromConfig();
|
||||||
?>
|
?>
|
||||||
<div id="menu" data-base-target="_main">
|
<div id="menu" data-base-target="_main">
|
||||||
|
|
|
@ -81,12 +81,14 @@ class ActionController extends Zend_Controller_Action
|
||||||
|
|
||||||
private $window;
|
private $window;
|
||||||
|
|
||||||
protected $isRedirect = false;
|
private $rerenderLayout = false;
|
||||||
|
|
||||||
protected $params;
|
private $xhrLayout = 'inline';
|
||||||
|
|
||||||
private $auth;
|
private $auth;
|
||||||
|
|
||||||
|
protected $params;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor starts benchmarking, loads the configuration and sets
|
* The constructor starts benchmarking, loads the configuration and sets
|
||||||
* other useful controller properties
|
* other useful controller properties
|
||||||
|
@ -109,7 +111,10 @@ class ActionController extends Zend_Controller_Action
|
||||||
|
|
||||||
$this->handlerBrowserWindows();
|
$this->handlerBrowserWindows();
|
||||||
$this->view->translationDomain = 'icinga';
|
$this->view->translationDomain = 'icinga';
|
||||||
$this->_helper->layout()->isIframe = (bool) $this->params->shift('isIframe', false);
|
$this->_helper->layout()->isIframe = $this->params->shift('isIframe');
|
||||||
|
if ($this->rerenderLayout = $this->params->shift('renderLayout')) {
|
||||||
|
$this->xhrLayout = 'body';
|
||||||
|
}
|
||||||
if ($this->requiresConfig()) {
|
if ($this->requiresConfig()) {
|
||||||
$this->redirectNow(Url::fromPath('install'));
|
$this->redirectNow(Url::fromPath('install'));
|
||||||
}
|
}
|
||||||
|
@ -171,6 +176,7 @@ class ActionController extends Zend_Controller_Action
|
||||||
protected function reloadCss()
|
protected function reloadCss()
|
||||||
{
|
{
|
||||||
$this->reloadCss = true;
|
$this->reloadCss = true;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -314,12 +320,16 @@ class ActionController extends Zend_Controller_Action
|
||||||
*/
|
*/
|
||||||
protected function redirectToLogin($afterLogin = '/dashboard')
|
protected function redirectToLogin($afterLogin = '/dashboard')
|
||||||
{
|
{
|
||||||
$url = Url::fromPath('/authentication/login');
|
$url = Url::fromPath('authentication/login');
|
||||||
if ($this->isXhr()) {
|
|
||||||
$url->setParam('_render', 'layout');
|
|
||||||
}
|
|
||||||
$url->setParam('redirect', $afterLogin);
|
$url->setParam('redirect', $afterLogin);
|
||||||
$this->redirectNow($url);
|
$this->rerenderLayout()->redirectNow($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rerenderLayout()
|
||||||
|
{
|
||||||
|
$this->rerenderLayout = true;
|
||||||
|
$this->xhrLayout = 'layout';
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isXhr()
|
public function isXhr()
|
||||||
|
@ -334,8 +344,18 @@ class ActionController extends Zend_Controller_Action
|
||||||
**/
|
**/
|
||||||
public function redirectNow($url)
|
public function redirectNow($url)
|
||||||
{
|
{
|
||||||
|
if (! $url instanceof Url) {
|
||||||
|
$url = Url::fromPath($url);
|
||||||
|
}
|
||||||
$url = preg_replace('~&~', '&', $url);
|
$url = preg_replace('~&~', '&', $url);
|
||||||
if ($this->isXhr()) {
|
if ($this->isXhr()) {
|
||||||
|
if ($this->rerenderLayout) {
|
||||||
|
$this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes');
|
||||||
|
}
|
||||||
|
if ($this->reloadCss) {
|
||||||
|
$this->getResponse()->setHeader('X-Icinga-Reload-Css', 'now');
|
||||||
|
}
|
||||||
|
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
->setHeader('X-Icinga-Redirect', rawurlencode($url))
|
->setHeader('X-Icinga-Redirect', rawurlencode($url))
|
||||||
->sendHeaders();
|
->sendHeaders();
|
||||||
|
@ -345,7 +365,6 @@ class ActionController extends Zend_Controller_Action
|
||||||
} else {
|
} else {
|
||||||
$this->_helper->Redirector->gotoUrlAndExit(Url::fromPath($url)->getRelativeUrl());
|
$this->_helper->Redirector->gotoUrlAndExit(Url::fromPath($url)->getRelativeUrl());
|
||||||
}
|
}
|
||||||
$this->isRedirect = true; // pretty useless right now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -384,7 +403,7 @@ class ActionController extends Zend_Controller_Action
|
||||||
protected function postDispatchXhr()
|
protected function postDispatchXhr()
|
||||||
{
|
{
|
||||||
$layout = $this->_helper->layout();
|
$layout = $this->_helper->layout();
|
||||||
$layout->setLayout('inline');
|
$layout->setLayout($this->xhrLayout);
|
||||||
$resp = $this->getResponse();
|
$resp = $this->getResponse();
|
||||||
|
|
||||||
$notifications = Notification::getInstance();
|
$notifications = Notification::getInstance();
|
||||||
|
@ -393,10 +412,10 @@ class ActionController extends Zend_Controller_Action
|
||||||
foreach ($notifications->getMessages() as $m) {
|
foreach ($notifications->getMessages() as $m) {
|
||||||
$notificationList[] = rawurlencode($m->type . ' ' . $m->message);
|
$notificationList[] = rawurlencode($m->type . ' ' . $m->message);
|
||||||
}
|
}
|
||||||
$resp->setHeader('X-Icinga-Notification: ' . implode('&', $notificationList));
|
$resp->setHeader('X-Icinga-Notification', implode('&', $notificationList));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->reloadCss || $this->getParam('_reload') === 'css') {
|
if ($this->reloadCss) {
|
||||||
$resp->setHeader('X-Icinga-CssReload', 'now');
|
$resp->setHeader('X-Icinga-CssReload', 'now');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,9 +430,8 @@ class ActionController extends Zend_Controller_Action
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getParam('_render') === 'layout') {
|
if ($this->rerenderLayout) {
|
||||||
$layout->setLayout('body');
|
$this->getResponse()->setHeader('X-Icinga-Container', 'layout');
|
||||||
$resp->setHeader('X-Icinga-Container', 'layout');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->autorefreshInterval !== null) {
|
if ($this->autorefreshInterval !== null) {
|
||||||
|
|
|
@ -441,7 +441,6 @@ class Monitoring_ListController extends Controller
|
||||||
{
|
{
|
||||||
$params = clone $this->params;
|
$params = clone $this->params;
|
||||||
|
|
||||||
$params->shift('_render');
|
|
||||||
$limit = $params->shift('limit');
|
$limit = $params->shift('limit');
|
||||||
$sort = $params->shift('sort');
|
$sort = $params->shift('sort');
|
||||||
$dir = $params->shift('dir');
|
$dir = $params->shift('dir');
|
||||||
|
@ -462,7 +461,7 @@ class Monitoring_ListController extends Controller
|
||||||
} else {
|
} else {
|
||||||
$filter->removeId($removeFilter);
|
$filter->removeId($removeFilter);
|
||||||
$redirect->setQueryString($filter->toQueryString())
|
$redirect->setQueryString($filter->toQueryString())
|
||||||
->getParams()->add('modifyFilter');;
|
->getParams()->add('modifyFilter');
|
||||||
}
|
}
|
||||||
$this->redirectNow($redirect);
|
$this->redirectNow($redirect);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,6 +234,15 @@
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addUrlFlag: function(url, flag)
|
||||||
|
{
|
||||||
|
if (url.match(/\?/)) {
|
||||||
|
return url + '&' + flag;
|
||||||
|
} else {
|
||||||
|
return url + '?' + flag;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
processRedirectHeader: function(req) {
|
processRedirectHeader: function(req) {
|
||||||
var redirect = req.getResponseHeader('X-Icinga-Redirect');
|
var redirect = req.getResponseHeader('X-Icinga-Redirect');
|
||||||
if (! redirect) return false;
|
if (! redirect) return false;
|
||||||
|
@ -241,7 +250,13 @@
|
||||||
'Got redirect for ', req.$target, ', URL was ' + redirect
|
'Got redirect for ', req.$target, ', URL was ' + redirect
|
||||||
);
|
);
|
||||||
redirect = decodeURIComponent(redirect);
|
redirect = decodeURIComponent(redirect);
|
||||||
this.loadUrl(redirect, req.$target);
|
|
||||||
|
if (req.getResponseHeader('X-Icinga-Rerender-Layout')) {
|
||||||
|
var redirectionUrl = this.addUrlFlag(redirect, 'renderLayout');
|
||||||
|
this.loadUrl(redirectionUrl, $('#layout')).url = redirect;
|
||||||
|
} else {
|
||||||
|
this.loadUrl(redirect, req.$target);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue