diff options
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/archive.php | 6 | ||||
| -rw-r--r-- | controllers/list.php | 3 | ||||
| -rw-r--r-- | controllers/login.php | 4 | ||||
| -rw-r--r-- | controllers/meta.php | 20 |
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(); |
