getTemplateHTML(); //pour charger le dernier theme utilisé sur le poste par l'appli const currentTheme = localStorage.getItem('theme') || null; if (currentTheme) { $("link#sigmr-theme-style").attr("href",$("style#theme-"+currentTheme).attr('data-url')); } // on nettoie le localStorage localKeys = Object.keys(localStorage), i = localKeys.length; while ( i-- ) { if (localKeys[i].startsWith('CC_')) { localStorage.removeItem(localKeys[i]); } else if (localKeys[i].startsWith('COUCHE_')) { localStorage.removeItem(localKeys[i]); }else if (localKeys[i].startsWith('LOT_')) { localStorage.removeItem(localKeys[i]); } } localStorage.removeItem("AUTH"); function saveTokenToLocalStorage() { var datas = $("#authen").serialize(); var url = "/greenalp/login?action=getTokenFromLogin"; $.ajax({ url: url, dataType:"json", data: datas, async: false, method:"POST", success: function(json) { var token=json.accessToken; //console.log("token stocké") localStorage.setItem('AUTH', JSON.stringify(json)); }, error: function(req,textStatus,errorThrown){ } }); } const authStepMinTimeout = 300; const authStepMaxDelta = 100; const getRandomTimeoutDuration = () => { return authStepMinTimeout + (Math.random() * authStepMaxDelta) } const bullshitAuthSteps = [ "Merci de patienter, chargement en cours", "Initialisation générale", "Connexion aux API externes", "Interfaçage avec la base de données", "Chargement des données cartographiques", "Chargement des données utilisateur", ]; const showLoginLoading = () => { $("#logo-login").removeClass("logo-appli").addClass("logo-appli-wait"); $("#text-login-attente").html("
...
") $(".progress-bar").attr("aria-valuenow", 0); $(".progress-bar").width(0 + "%"); $("#progress-login").removeClass("hidden"); let currentStep = 0 const showNextAuthStep = () => { const progress = 100 * (currentStep / bullshitAuthSteps.length) $("#text-login-attente").html("
" + bullshitAuthSteps[currentStep] + "...
") $(".progress-bar").attr("aria-valuenow", progress); $(".progress-bar").width(progress + "%"); setTimeout(() => { currentStep += 1 if(currentStep < bullshitAuthSteps.length){ showNextAuthStep() } else { $(".progress-bar").attr("aria-valuenow", 100); $(".progress-bar").width("100%"); } }, getRandomTimeoutDuration()) } showNextAuthStep() } const hideLoginLoading = () => { $("#progress-login").addClass("hidden"); } function getTemplateHTML() { $("#SYS_LOGIN_INPUTS").addClass("hidden"); $.ajax({ type: "POST", dataType: "html", contentType: "application/x-www-form-urlencoded; charset=UTF-8", url: "/greenalp/login?action=getTemplateHtml", success: function(html) { if (html==""){ html="<##SYS_LOGIN_INPUTS##>" } var zz=$("#SYS_LOGIN_INPUTS").clone().html(); html=html.replace("<##SYS_LOGIN_INPUTS##>",zz) $("#SYS_LOGIN_INPUTS").empty(); $("#htmlTemplate").parent().empty().html(html); $("#SYS_LOGIN_INPUTS").removeClass("hidden"); setTriggerOnInputs(); }, error: function(req, textStatus, errorThrown){ hideLoginLoading(); } }); } function actionLogin() { $("#divAlert").addClass("hidden"); $.ajax({ url: "/greenalp/login?action=login", type: "POST", data: { login : $("#inputLogin").val(), pwd : $("#inputPassword").val() }, dataType: "text", contentType: "application/x-www-form-urlencoded; charset=UTF-8", success: function(result) { var data = result.split("##"); if (data[0]=="URL"){ saveTokenToLocalStorage(); window.location=data[1]; } else { $(".body-login").empty().html(result); } }, error: function(req,textStatus,errorThrown){ hideLoginLoading(); $("#divAlert").removeClass("hidden"); $("#alertMessage").html(req.responseText); } }); } const onLoginValidation = () => { showLoginLoading() actionLogin(); } function setTriggerOnInputs() { $("#inputPassword, #inputLogin").on("keyup", function(e) { if(e.originalEvent.key == "Enter"){ e.preventDefault(); onLoginValidation() } }); $("#validation").on("click", function(e) { e.preventDefault(); onLoginValidation() }); }