82 lines
4.9 KiB
JavaScript
82 lines
4.9 KiB
JavaScript
$(document).ready(function(){
|
|
// Allow user to press enter to submit credentials
|
|
$('#username, #password').keypress(function(event) {
|
|
if (event.which === 13) {
|
|
$('#btnlogin').trigger('click');
|
|
}
|
|
});
|
|
|
|
$('#btnlogin').click(function() {
|
|
// Give feedback that request has been submitted (and prevent repeated requests)
|
|
$('#btnlogin').prop('disabled', true).css({
|
|
'background': '#999 url(data:image/gif;base64,R0lGODlhEAAQAPIAAJmZmf///7CwsOPj4////9fX18rKysPDwyH+GkNyZWF0ZWQgd2l0aCBhamF4bG9hZC5pbmZvACH5BAAKAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQACgABACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkEAAoAAgAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkEAAoAAwAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkEAAoABAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQACgAFACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQACgAGACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAAKAAcALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==) no-repeat center',
|
|
'color': 'transparent',
|
|
'transform': 'rotateX(180deg)'
|
|
});
|
|
$.post("lucidAuth.login.php", {
|
|
do: "login",
|
|
username: $('#username').val(),
|
|
password: $('#password').val(),
|
|
ref: $('#ref').val()
|
|
})
|
|
.done(function(data,_status) {
|
|
if (data.Result === 'Success') {
|
|
$('#btnlogin').css({
|
|
'background': 'green url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAaklEQVQ4jeXOMQ5AQBBG4T2BC4i76EWich7ncAKbqCRuodTqnMNTkFgJs3ZU4tXz/Rlj/hUQv8EpMAClFk9sjUAiHVcCnoFMwhZYgPYG575Xe46aIOyMdJx7ji9GwrEzUgOFCu8DkRp/qxU2BKCUyZR6ygAAAABJRU5ErkJggg==) no-repeat center',
|
|
'transform': 'rotateX(0deg)'
|
|
});
|
|
setTimeout(function() {
|
|
$('#btnlogin').prop('disabled', false).css({
|
|
'background': '#003399 linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 50%, rgba(255,255,255,0.25) 51%) no-repeat center',
|
|
'color': '#FFF'
|
|
});
|
|
if (data.CrossDomainLogin) {
|
|
var cookieDomains = JSON.parse(data.CookieDomains);
|
|
var XHR = [];
|
|
cookieDomains.forEach(function(domain) {
|
|
XHR.push($.get({
|
|
url: "https://auth." + domain + "/lucidAuth.requestCookie.php",
|
|
crossDomain: true,
|
|
xhrFields: {
|
|
withCredentials: true,
|
|
},
|
|
timeout: 750,
|
|
// origin domain should be exempted from timeout
|
|
// (because origin domain can/will be different from current domain --due to traefik design).
|
|
data: {
|
|
ref: btoa(JSON.stringify({
|
|
action: 'login',
|
|
token: data.SecureToken
|
|
}))
|
|
}
|
|
}).done(function() {
|
|
NProgress.inc(1 / XHR.length);
|
|
}));
|
|
});
|
|
$.when.apply($, XHR).then(function(){
|
|
$.each(arguments, function(_index, _arg) {
|
|
// Finished cross-domain logins (either succesfully or through timeout)
|
|
NProgress.done();
|
|
window.location.replace(data.Location);
|
|
});
|
|
});
|
|
}
|
|
}, 2250);
|
|
} else {
|
|
$('#btnlogin').css({
|
|
'background': 'red url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAv0lEQVQ4jaWT0Q3CMAxELwh1BEag87AJ6hcLlE/KBLABrNEV2h26QaXHj4NMGgpS7sfJJXd24kQqRMiRQC3pIKk2apD0DCEMq25ABZyBmSVmW6vWxH1GmKLPmph7xJQReq5dnNmVPQE7oHOCzrhoMts9vQ1OSbYOCBb92OPkDe6ZkqMwJwa4SdJmtS1/YGsx7e9VUiPpYvPG4tHtGUsvcf+RkpI2mkHZQ3ImLd+fcpuKf32meM5R0iOEMOb2F+EF33vgCePVr8UAAAAASUVORK5CYII=) no-repeat center',
|
|
'transform': 'rotateX(0deg)'
|
|
});
|
|
setTimeout(function() {
|
|
$('#btnlogin').prop('disabled', false).css({
|
|
'background': '#003399 linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 50%, rgba(255,255,255,0.25) 51%) no-repeat center',
|
|
'color': '#FFF'
|
|
});
|
|
// TODO: Add feedback (based on data.Reason)
|
|
// Is the redirect needed?
|
|
window.location.replace('lucidAuth.login.php'/*+ '?reason=' + data.Reason*/);
|
|
}, 2250);
|
|
}
|
|
});
|
|
});
|
|
}); |