Website Summary Files Commits Branches @commit @diff @stats
path: root / views / global / router.php
diff options
context:
space:
mode:
Commita6f29034d18d5a5ce48d879845cce3544b0f8a3c (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-02-02 09:46:44 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-02-02 09:46:44 +0200
Files8114c4ca6af34e04ecbab67a2359be7d92951db7 /views/global/router.php
nowayforward_human-a6f29034d18d5a5ce48d879845cce3544b0f8a3c.tar
nowayforward_human-a6f29034d18d5a5ce48d879845cce3544b0f8a3c.tar.gz
nowayforward_human-a6f29034d18d5a5ce48d879845cce3544b0f8a3c.zip
Parent40b78735aeba6082363e6a8d98b78da9ba230687 (diff)
feat: Create require_login helper function and improve list update page
1 files changed, 12 insertions, 0 deletions
-rw-r--r--views/global/router.php12
diff --git a/views/global/router.php b/views/global/router.php
index 9025113..527ad68 100644
--- a/views/global/router.php
+++ b/views/global/router.php
@@ -55,6 +55,18 @@ foreach (glob($MODELS_DIR . '/*.php') as $filename) {
$TOKEN = (array_key_exists('token', $_COOKIE)) ? ($_COOKIE['token'] ?? "") : ("");
+function redirect(string $href) {
+ echo '<script type="text/javascript">window.location.href = "' . $href . '";</script>';
+ exit;
+}
+
+function require_login() {
+ global $TOKEN;
+ if ($TOKEN === '') {
+ redirect('/login');
+ }
+}
+
if (str_ends_with($view, '.php')) {
require_once $view;
}