2019-02-28 14:31:10 +00:00
|
|
|
$(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) {
|
2019-06-19 10:09:46 +00:00
|
|
|
var cookieDomains = JSON.parse(data.CookieDomains);
|
|
|
|
var XHR = [];
|
|
|
|
cookieDomains.forEach(function(domain) {
|
|
|
|
XHR.push($.get({
|
2019-06-19 10:37:20 +00:00
|
|
|
url: "https://auth." + domain + "/lucidAuth.requestCookie.php",
|
2019-06-19 10:09:46 +00:00
|
|
|
crossDomain: true,
|
2019-06-19 10:34:31 +00:00
|
|
|
xhrFields: {
|
|
|
|
withCredentials: true,
|
|
|
|
},
|
2019-06-19 13:27:00 +00:00
|
|
|
timeout: 750,
|
|
|
|
// origin domain should be exempted from timeout
|
|
|
|
// (because origin domain can/will be different from current domain --due to traefik design).
|
2019-06-19 10:09:46 +00:00
|
|
|
data: {
|
|
|
|
ref: btoa(JSON.stringify({
|
|
|
|
action: 'login',
|
|
|
|
token: data.SecureToken
|
|
|
|
}))
|
|
|
|
}
|
2019-12-06 13:13:35 +00:00
|
|
|
}).done(function(_data, _textStatus, jqXHR) {
|
2019-06-19 13:27:00 +00:00
|
|
|
NProgress.inc(1 / XHR.length);
|
2019-12-06 13:13:35 +00:00
|
|
|
console.log('CrossDomain login succeeded for domain `' + domain + '` [' + JSON.stringify(jqXHR) + ']');
|
|
|
|
}).fail(function(jqXHR) {
|
|
|
|
console.log('CrossDomain login failed for domain `' + domain + '` [' + JSON.stringify(jqXHR) + ')]');
|
2019-06-20 08:02:42 +00:00
|
|
|
// Should check why this failed (timeout or bad request?), and if this is the origin domain, take action
|
2019-06-19 10:09:46 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
$.when.apply($, XHR).then(function(){
|
2019-06-19 10:55:01 +00:00
|
|
|
$.each(arguments, function(_index, _arg) {
|
2019-12-06 13:13:35 +00:00
|
|
|
// Finished cross-domain logins (either successfully or through timeout)
|
2019-06-19 13:27:00 +00:00
|
|
|
NProgress.done();
|
2019-12-06 13:13:35 +00:00
|
|
|
console.log('CrossDomain login completed; forwarding to `' + data.Location + '`');
|
2019-06-19 13:27:00 +00:00
|
|
|
window.location.replace(data.Location);
|
2019-06-19 10:09:46 +00:00
|
|
|
});
|
|
|
|
});
|
2019-02-28 14:31:10 +00:00
|
|
|
}
|
|
|
|
}, 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-01-16 10:37:35 +00:00
|
|
|
});
|