From 787ad114214b8563abfba812643da3a2a70708f9 Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Fri, 11 Oct 2024 15:16:11 -0700 Subject: [PATCH] Remove special casing for /a/authenticate page (#1619) --- files/app/main/authenticate.ut | 26 +++++++++++--------------- files/app/partial/login.ut | 16 ++-------------- files/app/root.ut | 2 +- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/files/app/main/authenticate.ut b/files/app/main/authenticate.ut index 0f7b0fc1..36992bb6 100755 --- a/files/app/main/authenticate.ut +++ b/files/app/main/authenticate.ut @@ -34,23 +34,19 @@ %} {% response.headers["Content-Type"] = "application/json"; -if (request.env.REQUEST_METHOD === "POST") { - try { - const j = json(uhttpd.recv(1024)); - if (j.version === 1) { - if (j.logout) { - auth.deauthenticate(); - print('{"authenticated":false}\n'); - return; - } - if (auth.authenticate(j.password)) { - print('{"authenticated":true}\n'); - return; - } - } +try { + if (match(request.env.QUERY_STRING, /^version=1&logout=1$/)) { + auth.deauthenticate(); + print('{"authenticated":false}\n'); + return; } - catch (_) { + const m = match(request.env.QUERY_STRING, /^version=1&password=(.+)$/); + if (m && auth.authenticate(uhttpd.urldecode(m[1]))) { + print('{"authenticated":true}\n'); + return; } } +catch (_) { +} print('{"authenticated":false}\n'); %} diff --git a/files/app/partial/login.ut b/files/app/partial/login.ut index cf8673d1..9cff6da9 100755 --- a/files/app/partial/login.ut +++ b/files/app/partial/login.ut @@ -63,13 +63,7 @@ loginDialog.close(); } else { - fetch(`${location.origin}/a/authenticate`, { - method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ version: 1, password: document.querySelector("#login input").value }) - }).then(function(response) { + fetch(`${location.origin}/a/authenticate?version=1&password=${encodeURIComponent(document.querySelector("#login input").value)}`).then(function(response) { if (response.status === 200) { response.json().then(function(json) { loginInput.value = ""; @@ -115,13 +109,7 @@