$(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) { console.log('CrossDomainLogin initiated'); // For reference: // [ // "Result" => "Success", // "Location" => $originalUri, // "CrossDomainLogin" => $settings->Session['CrossDomainLogin'], // "CookieDomains" => json_encode(array_diff($settings->Session['CookieDomains'], $_SERVER['HTTP_HOST'])) // ]); var cookieDomains = json_decode(data.CookieDomains); console.log(data.CookieDomains); // let the client setup multiple iframes for all domains // psuedo-code: foreach (cookieDomains as domain) { $.get(domain, ref=[action,token])} // validate each request against JWT-tokens in database // load all iframes parallel, show user progress and redirect once all iframes have finished loading; or after treshold of X ms has been reached // origin domain should be exempted from the treshold (because origin domain can be different from current domain -due to traefik design). } // Finished (either succesfully or through timeout) cross-domain logins 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); } }); }); });