redirUrl() and warning when not logged in on a form

This commit is contained in:
Miraty 2022-06-15 12:42:30 +02:00
parent 90d8e2fce7
commit 40cb0729ad
2 changed files with 10 additions and 1 deletions

View file

@ -50,7 +50,7 @@ foreach (array_diff(scandir(CONF['common']['root_path'] . "/public/css"), array(
<?php if (isset($_SESSION['username'])) { ?>
🆔 <strong><?= $_SESSION['username'] ?></strong> <a class='auth' href='<?= CONF['common']['prefix'] ?>/auth/logout'>Se déconnecter</a>
<?php } else { ?>
<span aria-hidden="true">👻 </span><em>Anonyme</em> <a class="auth" href="<?= CONF['common']['prefix'] ?>/auth/login?redir=<?php if (SERVICE !== "") echo SERVICE . "/"; ?><?= PAGE ?>">Se connecter</a>
<span aria-hidden="true">👻 </span><em>Anonyme</em> <a class="auth" href="<?= redirUrl('auth/login') ?>">Se connecter</a>
<?php } ?>
</p>
<nav>

View file

@ -17,6 +17,8 @@ function serverError($msg) {
// For use in pages that first display a form and then process it
function switchToFormProcess($requireLogin = true) {
if (empty($_POST) AND $requireLogin AND !isset($_SESSION['username']))
echo '<p>Ce formulaire ne sera pas accepté car il faut <a class="auth" href="' . redirUrl('auth/login') . '">se connecter</a> avant.</p>';
if (empty($_POST))
closeHTML();
if ($requireLogin AND !isset($_SESSION['username']))
@ -67,3 +69,10 @@ function displayIndex() { ?>
</dl>
<?php
}
function redirUrl($pageId) {
$currentPath = '';
if (SERVICE !== '') $currentPath .= SERVICE . '/';
if (PAGE !== 'index') $currentPath .= PAGE;
return CONF['common']['prefix'] . "/$pageId?redir=$currentPath";
}