Browse Source

web - form usability

master
Ruben Meyer 2 years ago
parent
commit
a3e626a274
Signed by: rxbn_ GPG Key ID: BE3BF898BE352FE2
  1. 3
      bin/web/views/login.pug
  2. 17
      res/web/js/custom.js

3
bin/web/views/login.pug

@ -13,7 +13,7 @@ append content
#login_msg.uk-alert(data-uk-alert).uk-hidden
a.uk-close-alt.uk-alert-close(href="#")
p
form.uk-form-horizontal
form.uk-form-horizontal(onsubmit="return loginEvent();")
.uk-margin
label.uk-form-label(for="login_user") Username / Email
.uk-form-controls
@ -22,6 +22,7 @@ append content
label.uk-form-label(for="login_pass") Password
.uk-form-controls
input.uk-input#login_pass(type="password")
input(hidden,type="submit")
button(onclick="login()").uk-button.uk-button-default Login
div(class="uk-width-auto [email protected]")
else

17
res/web/js/custom.js

@ -1,3 +1,7 @@
function loginEvent() {
login();
return false;
}
function login() {
let user = document.getElementById("login_user").value;
let pass = document.getElementById("login_pass").value;
@ -14,15 +18,20 @@ function login() {
ajax.onload = () => {
let json = JSON.parse(ajax.responseText);
let box = document.getElementById("login_msg");
box.classList.remove("uk-hidden");
box.classList.remove("uk-alert-success");
box.classList.remove("uk-alert-danger");
if(json.message && json.message == "msg.auth.login.successful") {
if(window.location.pathname == "/authenticate" && getParameterByName("appId")) window.location.href= "/authenticate";
else window.location.href= "/";
setTimeout(function () {
if(window.location.pathname == "/authenticate" && getParameterByName("appId")) window.location.href= "/authenticate";
else window.location.href= "/";
}, 150);
box.classList.remove("uk-hidden");
box.classList.add("uk-alert-success");
box.getElementsByTagName("p")[0].innerHTML = "Logged in. You will be redirected";
} else if(json.message && json.message == "msg.auth.login.failed") {
box.classList.remove("uk-hidden");
box.classList.add("uk-alert-danger");
box.getElementsByTagName("p")[0].innerHTML = "Login failed.<br> Username or Password is wrong.";
}

Loading…
Cancel
Save