Skip to content

Commit 8fd77cc

Browse files
committed
Add general page links and redirect on login/logout
1 parent 6fb5f06 commit 8fd77cc

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

src/WebApp/Application.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,16 @@ public function getAllowedTestType() {
248248
*/
249249

250250
/**
251-
* Used for protected pages: returns the URI where login shall be performed.
252-
* @return the URI or NULL when login is performed on same page.
251+
* Returns special defined page links or URIs for usage in various
252+
* contexts. Mostly used is 'login', 'logout', 'forget_password', 'home'.
253+
* @param string $key - key of the link
254+
* @return the page link, URI or NULL.
253255
*/
254-
public function getLoginUri() {
256+
public function getPageLink($key) {
257+
if ($this->config->has('pageLinks')) {
258+
$links = $this->config->get('pageLinks');
259+
if (isset($links->$key)) return $links->$key;
260+
}
255261
return NULL;
256262
}
257263

src/WebApp/BootstrapTheme/DefaultLayout.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ protected function renderNavbarContent() {
9292
}
9393
//$rc .= '<span class="navbar-text align-middle">'.$principal->__toString().'<a class="px-2" href="?logout"><i class="fas fa-sign-out-alt fa-lg"></i></a></span>';
9494
$rc .= '</ul>';
95-
} else if ($this->app->getLoginUri() != NULL) {
96-
$uri = $this->app->request->uri;
97-
if ($this->app->request->path == $this->app->getLoginUri()) {
95+
} else if ($this->app->getPageLink('login') != NULL) {
96+
$uri = $this->app->request->uri;
97+
$login = Utils::getAppPath($this->app->getPageLink('login'));
98+
if ($this->app->request->path == $login) {
9899
$uri = $this->app->request->path;
99100
} else {
100-
$uri = $this->app->getLoginUri().'?return='.urlencode($this->app->request->uri);
101+
$uri = $login.'?return='.urlencode($this->app->request->uri);
101102
}
102103
$rc .= '<span class="navbar-text align-middle"><a class="px-2" href="'.$uri.'">'.I18N::_('login_label').'</a></span>';
103104
}

src/WebApp/Page.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ public function getLayoutName() {
8787
public function processRequest() {
8888
if ($this->request->getPostParam('action') == 'login') {
8989
$this->processLoginAction();
90+
return array('redirect', $this->request->path);
9091
} else if ($this->request->hasGetParam('logout')) {
9192
$this->processLogoutAction();
93+
$home = $this->app->getPageLink('home');
94+
if ($home == NULL) $home = $this->request->path;
95+
else $home = Utils::getAppPath($home);
96+
return array('redirect', $home);
9297
}
9398

9499
$requiredRight = $this->getRequiredRight();
@@ -141,9 +146,12 @@ protected function computeDisplayMode() {
141146
if ($this->app->getPrincipal() == NULL) {
142147
// We need a login
143148
$this->display = 'login';
144-
$uri = $this->app->getLoginUri();
145-
if (($uri != NULL) && ($uri != $this->request->path)) {
146-
return array('redirect', $uri.'?return='.urlencode($this->request->uri));
149+
$uri = $this->app->getPageLink('login');
150+
if ($uri != NULL) {
151+
$uri = Utils::getAppPath($uri);
152+
if ($uri != $this->request->path) {
153+
return array('redirect', $uri.'?return='.urlencode($this->request->uri));
154+
}
147155
}
148156
} else if ($this->app->isAuthorized($requiredRight)) {
149157
// We can render

0 commit comments

Comments
 (0)