Remove special casing for /a/authenticate page (#1619)

This commit is contained in:
Tim Wilkinson 2024-10-11 15:16:11 -07:00 committed by GitHub
parent bdb3862dbb
commit 787ad11421
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 30 deletions

View File

@ -34,23 +34,19 @@
%} %}
{% {%
response.headers["Content-Type"] = "application/json"; response.headers["Content-Type"] = "application/json";
if (request.env.REQUEST_METHOD === "POST") { try {
try { if (match(request.env.QUERY_STRING, /^version=1&logout=1$/)) {
const j = json(uhttpd.recv(1024)); auth.deauthenticate();
if (j.version === 1) { print('{"authenticated":false}\n');
if (j.logout) { return;
auth.deauthenticate();
print('{"authenticated":false}\n');
return;
}
if (auth.authenticate(j.password)) {
print('{"authenticated":true}\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'); print('{"authenticated":false}\n');
%} %}

View File

@ -63,13 +63,7 @@
loginDialog.close(); loginDialog.close();
} }
else { else {
fetch(`${location.origin}/a/authenticate`, { fetch(`${location.origin}/a/authenticate?version=1&password=${encodeURIComponent(document.querySelector("#login input").value)}`).then(function(response) {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ version: 1, password: document.querySelector("#login input").value })
}).then(function(response) {
if (response.status === 200) { if (response.status === 200) {
response.json().then(function(json) { response.json().then(function(json) {
loginInput.value = ""; loginInput.value = "";
@ -115,13 +109,7 @@
<script> <script>
document.querySelector("#logout-icon .menu > div:first-child").addEventListener("click", function() document.querySelector("#logout-icon .menu > div:first-child").addEventListener("click", function()
{ {
fetch(`${location.origin}/a/authenticate`, { fetch(`${location.origin}/a/authenticate?version=1&logout=1`).then(function(response) {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ version: 1, logout: true })
}).then(function(response) {
location.reload(); location.reload();
}); });
}); });

View File

@ -446,7 +446,7 @@ global.handle_request = function(env)
uhttpd.send("Status: 401 Unauthorized\r\n\r\n"); uhttpd.send("Status: 401 Unauthorized\r\n\r\n");
return; return;
} }
if (env.REQUEST_METHOD !== "GET" && configuration.isConfigured() && page !== "authenticate") { if (env.REQUEST_METHOD !== "GET" && configuration.isConfigured()) {
uhttpd.send("Status: 401 Unauthorized\r\n\r\n"); uhttpd.send("Status: 401 Unauthorized\r\n\r\n");
return; return;
} }