$bIsFormSubmitting = false; jQuery(document).ready(function($) { //swal.close(); $('.field input').focusin(function() { $(this).addClass('on-focus'); }).focusout(function() { $(this).removeClass('on-focus'); }); $('.field select').focusin(function() { $(this).addClass('on-focus'); }).focusout(function() { $(this).removeClass('on-focus'); }); var $form = $('form'); $(document).keyup(function(e) { if(e.which == 13) $form.trigger('submit'); }); $form.find('#sign-in').click(function() { $form.trigger('submit'); }); $form.submit(function(e) { e.preventDefault(); if($bIsFormSubmitting) return false; $bIsFormSubmitting = true; var bIsFormValid = true; var sLastCustomerLogin = ""; $(this).find("input").each(function(index) { var sFieldParent = $(this).closest('.field'); var sFieldType = $(this).attr("type"); var sFieldValue = $(this).val(); if(sFieldType == "text") $(this).val(sLastCustomerLogin = sFieldValue = sFieldValue.trim().toUpperCase()); else if(sFieldType == "password") { var nLastCustomerLoginID = sLastCustomerLogin.length > 0 ? sLastCustomerLogin.replace("gs-","").replace("GS-","") : 0; if(nLastCustomerLoginID < 500000) { sFieldValue = sFieldValue.trim().toUpperCase(); $(this).val(sFieldValue); } } console.log(sFieldValue.length); console.log(sFieldParent.get(0)); if(sFieldValue.length < 1 || sFieldValue === 'GS-') { bIsFormValid = false; sFieldParent.addClass('on-error'); sFieldParent.find('p.error-message').text('Obbligatorio'); } else { sFieldParent.removeClass('on-error'); sFieldParent.find('p.error-message').text(''); } }); if(!bIsFormValid) { $bIsFormSubmitting = false; return false; } swal({ imageUrl: "https://gecid.gecsoftware.it/assets/images/preloaders/concentric.svg", title: "", text: "Accesso in corso, attendi", showConfirmButton: false, customClass: "loader", allowEscapeKey: false, allowOutsideClick: false, allowEnterKey: false, }); $.ajax({ type: "POST", url: "https://login.gecsoftware.it/gswcs/Customer/SignInWithLoginAndPassword.php", data: $form.serialize(), }).done(function($oJSON) { var urlredirect=localStorage.getItem("redirectUrl"); if(urlredirect == undefined || urlredirect == null || urlredirect=="") window.location.href = "https://gecid.gecsoftware.it/gswcs/customer/session/EntryPoint.php?CSAT="+encodeURIComponent($oJSON.Result)+"&RedirectTo="+encodeURIComponent('https://www.goform.it/accedi/?htt_ref=KvATm%2BgBqfd6%2BRY5wx1SqraO6zzkAz9ExX3I556skt6a%2FZbk59082R95XPMIkLL%2B&enr_to_wp_cou_id=13946'); else window.location.href=urlredirect; $bIsFormSubmitting = false; }).fail(function($oXHR) { $oJSON = $.parseJSON($oXHR.responseText.substring($oXHR.responseText.indexOf("{"))); if( $oJSON == undefined || $oJSON == null || ( !$oJSON.Details.ID.includes("404NF") && !$oJSON.Details.ID.includes("417W") ) ) ParseRESTAPIResponse($oJSON); else swal("ERRORE!", "Login sbagliato oppure Password sbagliata", "error"); $bIsFormSubmitting = false; }); return false; }); }); function ParseRESTAPIResponse($oRESTAPIResponse) { if($oRESTAPIResponse == null || $oRESTAPIResponse == undefined || $oRESTAPIResponse == null) { swal("ERRORE!", "Errore imprevisto. La risposta del Server non è stata inizializzata correttamente", "error"); return; } else if($oRESTAPIResponse.Details.ID.includes("200OK")) { swal("Okay", "La richiesta è stata portata a termine correttamente dal Server", "success"); } else if($oRESTAPIResponse.Details.ID.includes("404NF")) { swal("ERRORE!", "La risorsa richiesta non è stata trovata", "error"); } else if($oRESTAPIResponse.Details.ID.includes("417W")) { swal("ERRORE!", "La risorsa trovata non è compatibile con le specifiche richieste", "error"); } else if($oRESTAPIResponse.Details.ID.includes("400BR")) { swal("ERRORE!", "La richiesta è stata rifiutata dal Server in quanto non è formalmente valida", "error"); } else if($oRESTAPIResponse.Details.ID.includes("1NC")) { swal("ERRORE!", "Impossibile stabilire una connessione col Server", "error"); } else if($oRESTAPIResponse.Details.ID.includes("401U")) { swal("ERRORE!", "Non disponi dei permessi necessari per effettuare questa richiesta", "error"); } else if($oRESTAPIResponse.Details.ID.includes("2NIC")) { swal("ERRORE!", "Nessuna connessione ad Internet disponibile. Verifica le impostazioni di rete", "error"); } else { swal("ERRORE!", "Errore imprevisto. Si prega di aggiornare la pagina e riprovare", "error"); } }