Jelajahi Sumber

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

Miraty 3 tahun lalu
induk
melakukan
40cb0729ad
2 mengubah file dengan 10 tambahan dan 1 penghapusan
  1. 1 1
      common/html.php
  2. 9 0
      fn/common.php

+ 1 - 1
common/html.php

@@ -50,7 +50,7 @@ foreach (array_diff(scandir(CONF['common']['root_path'] . "/public/css"), array(
 <?php if (isset($_SESSION['username'])) { ?>
 <?php if (isset($_SESSION['username'])) { ?>
 				🆔 <strong><?= $_SESSION['username'] ?></strong> <a class='auth' href='<?= CONF['common']['prefix'] ?>/auth/logout'>Se déconnecter</a>
 				🆔 <strong><?= $_SESSION['username'] ?></strong> <a class='auth' href='<?= CONF['common']['prefix'] ?>/auth/logout'>Se déconnecter</a>
 <?php } else { ?>
 <?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 } ?>
 <?php } ?>
 			</p>
 			</p>
 			<nav>
 			<nav>

+ 9 - 0
fn/common.php

@@ -17,6 +17,8 @@ function serverError($msg) {
 
 
 // For use in pages that first display a form and then process it
 // For use in pages that first display a form and then process it
 function switchToFormProcess($requireLogin = true) {
 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))
 	if (empty($_POST))
 		closeHTML();
 		closeHTML();
 	if ($requireLogin AND !isset($_SESSION['username']))
 	if ($requireLogin AND !isset($_SESSION['username']))
@@ -67,3 +69,10 @@ function displayIndex() { ?>
 </dl>
 </dl>
 <?php
 <?php
 }
 }
+
+function redirUrl($pageId) {
+	$currentPath = '';
+	if (SERVICE !== '') $currentPath .= SERVICE . '/';
+	if (PAGE !== 'index') $currentPath .= PAGE;
+	return CONF['common']['prefix'] . "/$pageId?redir=$currentPath";
+}