From 76de68d2f3600a7000a054be3f595029b1931e20 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 26 Jan 2025 11:08:46 +0200 Subject: feat: Authentication logic on every page --- views/authenticate.js | 19 +++++++++++++++++++ views/footer.php | 13 +++++++++++++ views/header.php | 18 +++++++++++++++--- views/profile/authenticate.php | 27 +++++++++++++++++++++++++++ views/styles.css | 4 ++++ 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 views/authenticate.js create mode 100644 views/profile/authenticate.php (limited to 'views') diff --git a/views/authenticate.js b/views/authenticate.js new file mode 100644 index 0000000..5e1371a --- /dev/null +++ b/views/authenticate.js @@ -0,0 +1,19 @@ +var authentication_response = null; +var authentication_callbacks = []; + +function requestAuthentication() { + var request = new XMLHttpRequest(); + request.onreadystatechange = function() { + if (request.readyState < 4) return; + + authentication_response = (request.status == 200) ? request.responseText : ""; + } + request.open("POST", "/profile/authenticate.php", true); + request.setRequestHeader("Authorization", sessionStorage.getItem("token")); + request.send(null); +} +requestAuthentication(); + +function authenticated(callback) { + authentication_callbacks.push(callback); +} diff --git a/views/footer.php b/views/footer.php index b457da8..22c4631 100644 --- a/views/footer.php +++ b/views/footer.php @@ -1,3 +1,16 @@ + diff --git a/views/header.php b/views/header.php index 7a874d4..3835dfb 100644 --- a/views/header.php +++ b/views/header.php @@ -9,16 +9,28 @@ <?= htmlspecialchars($title ?? "No Way Forward Human");?> +
+
diff --git a/views/profile/authenticate.php b/views/profile/authenticate.php new file mode 100644 index 0000000..540d4a3 --- /dev/null +++ b/views/profile/authenticate.php @@ -0,0 +1,27 @@ +Username; +} +else { + http_response_code(401); + header('Content-Type: text/plain'); + echo 'Bad token!'; +} + +exit; diff --git a/views/styles.css b/views/styles.css index f1a24fe..5058854 100644 --- a/views/styles.css +++ b/views/styles.css @@ -70,6 +70,10 @@ input[type=submit]:hover { cursor: pointer; } +[hidden] { + display: none !important; +} + /* Generic */ .float-right { -- cgit v1.2.3