aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-01-26 22:00:21 +0200
committerSyndamia <kamen@syndamia.com>2025-01-26 22:21:31 +0200
commitedf446fae669f3370609f5a955c3d6c863a93524 (patch)
treec46984167cc5b79c51b243602f7a4837d428fd82 /controllers
parent73ad3e330be1a6849269fec5d4b7b42b0330cede (diff)
downloadnowayforward_human-edf446fae669f3370609f5a955c3d6c863a93524.tar
nowayforward_human-edf446fae669f3370609f5a955c3d6c863a93524.tar.gz
nowayforward_human-edf446fae669f3370609f5a955c3d6c863a93524.zip
feat: Replace sessionStorage with (custom) cookieStorage
Diffstat (limited to 'controllers')
-rw-r--r--controllers/archive.php6
-rw-r--r--controllers/list.php3
-rw-r--r--controllers/login.php4
-rw-r--r--controllers/meta.php20
4 files changed, 23 insertions, 10 deletions
diff --git a/controllers/archive.php b/controllers/archive.php
index dbce6c3..0941d12 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -5,13 +5,15 @@ use DOMDocument;
use Exception;
function on_post() {
+ global $TOKEN;
+
$WEBSITE_CATEGORY = 'page_url';
$DOWNLOADS_FOLDER = getenv('ARCHIVES_DIR');
$website_url = $_POST[$WEBSITE_CATEGORY];
$uid = 1;
- if (array_key_exists('token', $_POST) && strlen($_POST['token']) === 36) {
+ if ($TOKEN !== "") {
try {
- $uid = Database\Cookie::fromDB($_POST['token'])->UID;
+ $uid = Database\Cookie::fromDB($TOKEN)->UID;
}
catch (Exception $e) {}
}
diff --git a/controllers/list.php b/controllers/list.php
index 0ec33d1..2dea9ec 100644
--- a/controllers/list.php
+++ b/controllers/list.php
@@ -4,11 +4,12 @@ use Database;
use Exception;
function on_post() {
+ global $TOKEN;
global $list_status;
$list_status = "";
try {
- $uid = Database\Cookie::fromDB($_POST['token'])->UID;
+ $uid = Database\Cookie::fromDB($TOKEN)->UID;
Database\ArchiveList::create($uid, $_POST["name"], $_POST["description"]);
}
catch(Exception $e) {
diff --git a/controllers/login.php b/controllers/login.php
index 8b640ce..179afe6 100644
--- a/controllers/login.php
+++ b/controllers/login.php
@@ -23,9 +23,9 @@ function on_post() {
}
function on_delete() {
+ global $TOKEN;
try {
- $headers = apache_request_headers();
- Database\Cookie::delete($headers["Authorization"]);
+ Database\Cookie::delete($TOKEN);
}
catch(Exception $e) {}
}
diff --git a/controllers/meta.php b/controllers/meta.php
index e20bbfc..91a8ade 100644
--- a/controllers/meta.php
+++ b/controllers/meta.php
@@ -6,8 +6,18 @@ function call_handler(string $name) {
}
}
-switch ($_SERVER['REQUEST_METHOD']) {
- case 'POST': call_handler('Controller\on_post'); break;
- case 'PUT': call_handler('Controller\on_put'); break;
- case 'DELETE': call_handler('Controller\on_delete'); break;
-};
+$TOKEN = (array_key_exists('token', $_COOKIE)) ? ($_COOKIE['token'] ?? "") : ("");
+
+function request_handler() {
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ if (array_key_exists('method', $_POST)) {
+ switch ($_POST['method']) {
+ case 'PUT': call_handler('Controller\on_put'); return;
+ case 'DELETE': call_handler('Controller\on_delete'); return;
+ case 'PATCH': call_handler('Controller\on_patch'); return;
+ }
+ }
+ call_handler('Controller\on_post');
+ }
+}
+request_handler();