diff options
author | Devaev Maxim <[email protected]> | 2018-12-16 04:13:19 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-12-16 04:13:19 +0300 |
commit | 6626e514b391d672a6352bbd965a1b3d671ed487 (patch) | |
tree | 3097483623d03dfc48de8613bab9655ca130f57d /web/share/js/login | |
parent | d7fb06d22ebfad8134c5d1a1e2bd6f6001baf8c4 (diff) |
logout
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(); +} |