This commit is contained in:
Devaev Maxim
2018-12-16 04:13:19 +03:00
parent d7fb06d22e
commit 6626e514b3
7 changed files with 116 additions and 21 deletions

View File

@@ -1,12 +1,17 @@
var wm;
function main() {
if (checkBrowser()) {
wm = new WindowManager();
tools.setOnClick($("login-button"), __login);
document.onkeyup = function(event) {
$("user-input").onkeyup = $("passwd-input").onkeyup = function(event) {
if (event.code == "Enter") {
event.preventDefault();
__login();
}
};
$("user-input").focus();
}
}
@@ -15,17 +20,18 @@ function __login() {
var user = $("user-input").value;
var passwd = $("passwd-input").value;
var body = `user=${encodeURIComponent(user)}&passwd=${encodeURIComponent(passwd)}`;
var http = tools.makeRequest("POST", "/kvmd/auth/login", function() {
if (http.readyState === 4) {
if (http.status === 200) {
document.location.href = "/";
} else if (http.status === 403) {
wm.error("Invalid username or password").then(__tryAgain);
} else {
wm.error("Login error:<br>", http.responseText).then(__tryAgain);
}
__setDisabled(false);
$("passwd-input").focus();
$("passwd-input").select();
}
}, body, "application/x-www-form-urlencoded");
http.send();
__setDisabled(true);
}
@@ -34,3 +40,9 @@ function __setDisabled(disabled) {
$("passwd-input").disabled = disabled;
$("login-button").disabled = disabled;
}
function __tryAgain() {
__setDisabled(false);
$("passwd-input").focus();
$("passwd-input").select();
}