mirror of https://github.com/aredn/aredn.git
Remove special casing for /a/authenticate page (#1619)
This commit is contained in:
parent
bdb3862dbb
commit
787ad11421
|
@ -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');
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue