1
0
Fork 0

web - login messages

master
Ruben Meyer 2 years ago
parent 357dda7b5f
commit 84b94ac653
  1. 3
      bin/web/views/login.pug
  2. 25
      res/web/js/custom.js

@ -10,6 +10,9 @@ append content
div(class="uk-width-auto uk-width-1-4@s")
.uk-flex.uk-flex-auto.uk-flex-column.uk-flex-center.uk-margin-left.uk-margin-right
h1= login_title || "Please login"
#login_msg.uk-alert(data-uk-alert).uk-hidden
a.uk-close-alt.uk-alert-close(href="#")
p
form.uk-form-horizontal
.uk-margin
label.uk-form-label(for="login_user") Username / Email

@ -13,7 +13,19 @@ function login() {
ajax.send(JSON.stringify(data));
ajax.onload = () => {
let json = JSON.parse(ajax.responseText);
if(json.message && json.message == "msg.auth.login.successful") window.location.href= "/";
let box = document.getElementById("login_msg");
if(json.message && json.message == "msg.auth.login.successful") {
if(window.location.pathname == "/authenticate" && getParameterByName("appId")) window.location.href= "/authenticate";
else window.location.href= "/";
box.classList.remove("uk-hidden");
box.classList.add("uk-alert-success");
box.classList.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.";
}
};
};
@ -33,3 +45,14 @@ setTimeout(function () {
logout();
}
}, 100);
// @url: https://stackoverflow.com/a/901144
function getParameterByName(name) {
let url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

Loading…
Cancel
Save