Add the html-anchor from the url to the login redirection
Change the Url class to support html anchors and add JavaScript to fetch the anchor from the URL, as it is regularly not send to the server. refs #4833
This commit is contained in:
parent
bb64977a53
commit
6062d5f716
|
@ -58,8 +58,8 @@ class AuthenticationController extends ActionController
|
|||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
$this->replaceLayout = true;
|
||||
$credentials = new Credential();
|
||||
$this->_helper->layout->setLayout('inline');
|
||||
$this->view->form = new LoginForm();
|
||||
$this->view->form->setRequest($this->_request);
|
||||
$this->view->title = "Icinga Web Login";
|
||||
|
@ -98,10 +98,10 @@ class AuthenticationController extends ActionController
|
|||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
$this->_helper->layout->setLayout('inline');
|
||||
$auth = AuthManager::getInstance(null, array(
|
||||
'writeSession' => $this->modifiesSession
|
||||
));
|
||||
$this->replaceLayout = true;
|
||||
$auth->removeAuthorization();
|
||||
$this->redirectToLogin();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
<div class="well">
|
||||
<h1>Login</h1>
|
||||
|
||||
|
@ -10,3 +9,16 @@
|
|||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
/*
|
||||
* Preserve the html anchor when redirecting to the originally called link. This
|
||||
* is useful for preserving the detail view and the selection in that case.
|
||||
*
|
||||
* refs #4833
|
||||
*
|
||||
* TODO: Copy this snipped into the new login.phtml
|
||||
*/
|
||||
var url = document.URL.match(/(^[^#]*)/)[0] + encodeURIComponent(window.location.hash);
|
||||
document.getElementById('form_login').action = url;
|
||||
</script>
|
|
@ -50,13 +50,6 @@ use \Icinga\Web\Request;
|
|||
*/
|
||||
class ActionController extends Zend_Controller_Action
|
||||
{
|
||||
/**
|
||||
* True to mark this layout to not render the full layout
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $replaceLayout = false;
|
||||
|
||||
/**
|
||||
* Whether the controller requires the user to be authenticated
|
||||
*
|
||||
|
@ -171,13 +164,14 @@ class ActionController extends Zend_Controller_Action
|
|||
/**
|
||||
* Return the URI that can be used to request the current action
|
||||
*
|
||||
* @return string return the path to this action: <Module>/<Controller>/<Action>
|
||||
* @return string return the path to this action: <Module>/<Controller>/<Action>?<Query>
|
||||
*/
|
||||
public function getRequestUrl()
|
||||
{
|
||||
return $this->_request->getModuleName() . '/' .
|
||||
$this->_request->getControllerName() . '/' .
|
||||
$this->_request->getActionName();
|
||||
$base = $this->_request->getModuleName() . '/' .
|
||||
$this->_request->getControllerName() . '/' .
|
||||
$this->_request->getActionName();
|
||||
return $_SERVER['QUERY_STRING'] !== '' ? $base . '?' . $_SERVER['QUERY_STRING'] : $base;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,6 +31,13 @@ class Url
|
|||
*/
|
||||
private $params = array();
|
||||
|
||||
/**
|
||||
* The site anchor after the '#'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $anchor = '';
|
||||
|
||||
/**
|
||||
* The relative path of this Url, without query parameters
|
||||
*
|
||||
|
@ -108,7 +115,16 @@ class Url
|
|||
}
|
||||
$urlObject->setBaseUrl($request->getBaseUrl());
|
||||
|
||||
/*
|
||||
* Fetch fragment manually and remove it from the url, to 'help' the parse_url() function
|
||||
* parsing the url properly. Otherwise calling the function with a fragment, but without a
|
||||
* query will cause unpredictable behaviour.
|
||||
*/
|
||||
$fragment = self::getUrlFragment($url);
|
||||
$url = self::stripUrlFragment($url);
|
||||
|
||||
$urlParts = parse_url($url);
|
||||
|
||||
if (isset($urlParts["path"])) {
|
||||
$urlObject->setPath($urlParts["path"]);
|
||||
}
|
||||
|
@ -117,11 +133,43 @@ class Url
|
|||
parse_str($urlParts["query"], $urlParams);
|
||||
$params = array_merge($urlParams, $params);
|
||||
}
|
||||
if ($fragment !== '') {
|
||||
$urlObject->setAnchor($fragment);
|
||||
}
|
||||
|
||||
$urlObject->setParams($params);
|
||||
return $urlObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fragment of a given url
|
||||
*
|
||||
* @param $url The url containing the fragment.
|
||||
*
|
||||
* @return string The fragment without the '#'
|
||||
*/
|
||||
private static function getUrlFragment($url)
|
||||
{
|
||||
$url = parse_url($url);
|
||||
if (isset($url['fragment'])) {
|
||||
return $url['fragment'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the fragment-part of a given url
|
||||
*
|
||||
* @param $url string The url to strip from its fragment
|
||||
*
|
||||
* @return string The url without the fragment.
|
||||
*/
|
||||
private static function stripUrlFragment($url)
|
||||
{
|
||||
return preg_replace('/#.*$/', '', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the baseUrl.
|
||||
*
|
||||
|
@ -179,9 +227,9 @@ class Url
|
|||
public function getRelativeUrl()
|
||||
{
|
||||
if (empty($this->params)) {
|
||||
return ltrim($this->path, '/');
|
||||
return ltrim($this->path, '/') . $this->anchor;
|
||||
}
|
||||
return ltrim($this->path, '/').'?'.http_build_query($this->params);
|
||||
return ltrim($this->path, '/') . '?' . http_build_query($this->params) . $this->anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,6 +328,16 @@ class Url
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the url anchor-part
|
||||
*
|
||||
* @param $anchor The site's anchor string without the '#'
|
||||
*/
|
||||
public function setAnchor($anchor)
|
||||
{
|
||||
$this->anchor = '#' . $anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove provided key (if string) or keys (if array of string) from the query parameter array
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue