diff options
Diffstat (limited to 'web/share/js/login')
-rw-r--r-- | web/share/js/login/main.js | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/web/share/js/login/main.js b/web/share/js/login/main.js index dc45d03f..1362f821 100644 --- a/web/share/js/login/main.js +++ b/web/share/js/login/main.js @@ -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(); +} |