From edf446fae669f3370609f5a955c3d6c863a93524 Mon Sep 17 00:00:00 2001
From: Syndamia "= $url ?>" hasn't been archived yet!
-
diff --git a/views/authenticate.js b/views/authenticate.js
index 8b158ce..398794a 100644
--- a/views/authenticate.js
+++ b/views/authenticate.js
@@ -1,3 +1,25 @@
+var cookieStorage = {
+ getItem: function(index) {
+ let cookies = document.cookie.split(';');
+ for (cookie of cookies) {
+ let values = cookie.trim().split('=');
+ if (values[0] === index) {
+ return values[1];
+ }
+ }
+ return undefined;
+ },
+ setItem: function(index, value, expires = 'Fri, 31 Dec 9999 23:59:59 GMT') {
+ let cookie = index + '=' + value + ';';
+ cookie += 'expires=' + expires + ';';
+ cookie += 'path=/';
+ document.cookie = cookie;
+ },
+ removeItem: function(index) {
+ cookieStorage.setItem(index, "", 'Thu, 01 Jan 1970 00:00:00 GMT');
+ },
+};
+
var authentication_response = null;
var authentication_callbacks = [];
@@ -9,7 +31,6 @@ function requestAuthentication() {
authentication_response = (request.status == 200) ? request.responseText : "";
}
request.open("POST", "/authenticate", true);
- request.setRequestHeader("Authorization", sessionStorage.getItem("token"));
request.send(null);
}
requestAuthentication();
diff --git a/views/global/router.php b/views/global/router.php
index fa9348d..cd9b304 100644
--- a/views/global/router.php
+++ b/views/global/router.php
@@ -40,6 +40,8 @@ foreach (glob($MODELS_DIR . '/*.php') as $filename) {
require_once $filename;
}
+$TOKEN = (array_key_exists('token', $_COOKIE)) ? ($_COOKIE['token'] ?? "") : ("");
+
if (str_ends_with($view, '.php')) {
require_once $view;
}
diff --git a/views/login/index.php b/views/login/index.php
index 94faafe..da0d8e2 100644
--- a/views/login/index.php
+++ b/views/login/index.php
@@ -10,7 +10,7 @@