mirror of https://github.com/aredn/aredn.git
parent
02881f5baa
commit
ffda9117c2
|
@ -34,7 +34,8 @@
|
|||
%}
|
||||
{% if (!auth.isAdmin) { %}
|
||||
<dialog id="login">
|
||||
Password <input type="password"><button>OK</button>
|
||||
<div>Password <input type="password"><button>Dismiss</button></div>
|
||||
<div class="error"><div></div></div>
|
||||
</dialog>
|
||||
<div id="login-icon" class="popup-menu">
|
||||
<label title="Login as admin">
|
||||
|
@ -47,15 +48,21 @@
|
|||
</div>
|
||||
<script>
|
||||
const loginDialog = document.getElementById('login');
|
||||
const loginInput = loginDialog.querySelector("input");
|
||||
const loginButton = loginDialog.querySelector("button");
|
||||
const loginError = loginDialog.querySelector(".error > div");
|
||||
document.querySelector("#login-icon .menu > div").addEventListener("click", function()
|
||||
{
|
||||
loginInput.value = "";
|
||||
loginButton.innerText = "Dismiss";
|
||||
loginError.innerText = "";
|
||||
loginDialog.showModal();
|
||||
});
|
||||
loginDialog.addEventListener("close", function()
|
||||
{
|
||||
loginDialog.querySelector("input").value = "";
|
||||
});
|
||||
function doAuth() {
|
||||
if (loginInput.value === "") {
|
||||
loginDialog.close();
|
||||
}
|
||||
else {
|
||||
fetch(`${location.origin}/a/authenticate`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -65,16 +72,32 @@
|
|||
}).then(function(response) {
|
||||
if (response.status === 200) {
|
||||
response.json().then(function(json) {
|
||||
loginInput.value = "";
|
||||
loginButton.innerText = "Dismiss";
|
||||
if (json.authenticated) {
|
||||
loginDialog.close();
|
||||
location.replace(location.origin);
|
||||
}
|
||||
});
|
||||
else {
|
||||
loginError.innerText = "Incorrect password";
|
||||
}
|
||||
});
|
||||
loginDialog.close();
|
||||
}
|
||||
else {
|
||||
loginInput.value = "";
|
||||
loginButton.innerText = "Dismiss";
|
||||
loginError.innerText = "Login failure";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
loginDialog.querySelector('button').addEventListener("click", doAuth);
|
||||
loginDialog.querySelector('input').addEventListener("change", doAuth);
|
||||
loginDialog.querySelector('input').addEventListener("input", function()
|
||||
{
|
||||
loginError.innerText = "";
|
||||
loginButton.innerText = loginInput.value ? "OK" : "Dismiss";
|
||||
});
|
||||
</script>
|
||||
{% } else { %}
|
||||
<div id="logout-icon" class="popup-menu">
|
||||
|
|
|
@ -656,17 +656,43 @@ body.authenticated #local-and-neighbor-devices .status.ctrl:hover
|
|||
border-radius: 20px;
|
||||
background-color: var(--ctrl-modal-bg-tertiary-color);
|
||||
}
|
||||
#login input {
|
||||
#login > div
|
||||
{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
#login input
|
||||
{
|
||||
color: inherit;
|
||||
font-size: 14px;
|
||||
background-color: var(--ctrl-modal-textbox-bg-color);
|
||||
margin: 0 10px;
|
||||
outline: none;
|
||||
border: 1px solid var(--ctrl-modal-textbox-border-color);
|
||||
}
|
||||
#login button {
|
||||
#login button
|
||||
{
|
||||
position: relative;
|
||||
padding-top: 2px;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
font-size: 14px;
|
||||
color: inherit;
|
||||
background-color: var(--ctrl-modal-textbox-bg-color);
|
||||
min-width: 70px;
|
||||
border: 1px solid var(--ctrl-modal-textbox-border-color);
|
||||
}
|
||||
#login .error
|
||||
{
|
||||
position: relative;
|
||||
}
|
||||
#login .error > div
|
||||
{
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
padding-top: 26px;
|
||||
text-align: center;
|
||||
color: var(--ctrl-modal-border-color-error);
|
||||
z-index: -1;
|
||||
}
|
||||
#login::backdrop
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue