var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; $(document).ready(function () { var loginFormConfig = { rules: { txtLoginEmail: { required: true, email: true }, txtLoginPassword: "required" }, messages: { txtLoginEmail: { required: "Entrez votre email", email: "Entrez un email valide" }, txtLoginPassword: "Entrez votre mot de passe" } }; var registerFormConfig = { rules: { txtRegisterName: "required", txtRegisterSurname: "required", txtRegisterEmail: { required: true, email: true }, txtRegisterPassword: { required: true, minlength: 8 }, txtRegisterPasswordConfirm: { equalTo: "#txtRegisterPassword" } }, messages: { txtRegisterName: "Entrez votre prénom", txtRegisterSurname: "Entrez vos noms de famille", txtRegisterEmail: { required: "Entrez un email", email: "Entrez un email valide" }, txtRegisterPassword: { required: "Entrez un mot de passe", minlength: "Le mot de passe doit comporter au moins 8 caractères" }, txtRegisterPasswordConfirm: { equalTo: "Les mots de passe ne correspondent pas" } } }; $("form").validate({ ignore: ".ignore", errorClass: "form-error", rules: __assign(__assign({}, loginFormConfig.rules), registerFormConfig.rules), messages: __assign(__assign({}, loginFormConfig.messages), registerFormConfig.messages) }); $('#login-btn').click(function () { VPreSignIn(); }); $(document).keypress(function (e) { if (e.which == 13) { VPreSignIn(); } }); function VPreSignIn() { onlyValidateLoginForm(); if (!$('form').valid()) return; var data = { sEmail: $("#txtLoginEmail").val(), sPassword: $("#txtLoginPassword").val(), bRememberUser: true }; localStorage.setItem("email", data.sEmail); VSignIn(data); } function onlyValidateLoginForm() { $("input", "form").addClass("ignore"); $("input", "#login-form").removeClass("ignore"); } function VSignIn(data) { var $loginBtn = $('#login-btn'); $loginBtn.prop("disabled", "disabled"); $.ajax({ type: "POST", url: "/DoLogin.ashx", data: JSON.stringify(data), contentType: "application/json; charset=utf-8", dataType: "json", xhrFields: { withCredentials: true }, success: function (data) { if (!data.bError) { showSuccess("Salut, " + data.sUserName, "Entrer dans votre compte ..."); AuthToken.TokenHelper.saveTokenLocalStorage(data.sTokenJWT); window.location = data.sReturnURL; } else { showError("Error", data.sErrorMessage); $loginBtn.prop("disabled", false); } }, error: function (jqXHR, textStatus) { if (jqXHR.status === 0) { showError("Error", "Connection problem"); } else { showError("Error", "Unknown problem"); } $loginBtn.prop("disabled", false); } }); } $('#forgot-password').click(function () { var oCaptchaForgotPassword; Swal.fire({ title: "J´ai oublié mon mot de passe", html: "Entrez votre email et nous vous enverrons un lien pour réinitialiser le mot de passe." + '
', input: 'text', width: 400, showCancelButton: true, inputPlaceholder: "example@agroplanning.com", didOpen: function () { oCaptchaForgotPassword = grecaptcha.render('forgotPasswordRecaptcha', { 'sitekey': '6LdJbQwUAAAAABC-_DH0E0vtyQtLdVBCcq_u2RCx', hl: myLanguage, }); }, preConfirm: function (email) { if (!email) { showErrorEmailValidation(); } var sCaptchaResponse = grecaptcha.getResponse(oCaptchaForgotPassword); if (sCaptchaResponse.length === 0) { showErrorCaptchaValidation(); } return email; } }).then(function (result) { if (result.isConfirmed) { var data = { sEmail: result.value, sCaptchaValue: grecaptcha.getResponse(oCaptchaForgotPassword), sDomain: "my.agroplanning.com" }; $.ajax({ type: "POST", url: "/ForgotPassword.ashx", data: JSON.stringify(data), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { if (!data.bError) { showSuccess("Nice!", "Vérifiez votre boîte de réception " + result.value + " et suivez les instructions que nous vous avons envoyées."); } else { showError("Error", data.sErrorMessage); } }, error: function (jqXHR, textStatus) { if (jqXHR.status === 0) { showError("Error", "Connection problem"); } else { showError("Error", "Unknown problem"); } } }); } }); }); function showSuccess(title, message) { Swal.fire({ icon: 'success', title: title, text: message, showConfirmButton: false, timer: 2500 }); } function showError(title, message) { showSwal(title, message, 'error'); } function showWarning(title, message) { showSwal(title, message, 'warning'); } function showSwal(title, message, classCSS) { Swal.fire({ icon: classCSS, title: title, text: message, }); } function showErrorEmailValidation() { Swal.showValidationMessage('Votre email est requis'); } function showErrorCaptchaValidation() { Swal.showValidationMessage('Nous devons nous assurer que vous n´êtes pas un robot. S´il vous plaît, effectuez les actions nécessaires dans le "captcha".'); $('.swal2-inputerror').removeClass('swal2-inputerror'); $('.g-recaptcha').addClass('captcha-validation-err'); setTimeout(function () { $('.g-recaptcha').removeClass('captcha-validation-err'); }, 2000); } $('#sign-up-btn').click(function (e) { e.preventDefault(); $('#register-modal').modal('show'); }); $('#chkTerms').click(function () { if ($('#signUpRecaptcha').css("display") == "none") $('#signUpRecaptcha').css("display", "inline-block"); else return; grecaptcha.render('signUpRecaptcha', { 'sitekey': "6LdJbQwUAAAAABC-_DH0E0vtyQtLdVBCcq_u2RCx", hl: myLanguage, }); }); $('#register-btn').click(function (e) { e.preventDefault(); onlyValidateRegisterForm(); if (!$("form").valid()) { return false; } var agreeTerms = $("#chkTerms").prop("checked"); if (!agreeTerms) { showError("", "Vous devez accepter les termes et conditions."); return; } var sCaptchaResponse = grecaptcha.getResponse(); if (sCaptchaResponse.length == 0) { showErrorSignUpCaptchaValidation(); return; } var btnRegister = $(this); btnRegister.prop("disabled", "disabled"); var data = { sName: $("#txtRegisterName").val(), sSurname: $("#txtRegisterSurname").val(), sEmail: $("#txtRegisterEmail").val(), sPassword: $("#txtRegisterPassword").val(), sLanguage: myLanguage, sCaptchaValue: sCaptchaResponse, bAgreeTerms: true }; $.ajax({ type: "POST", url: "/RegisterNewUser.ashx", data: JSON.stringify(data), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { if (!data.bError) { showSuccess("", "Enregistrement terminé avec succès."); setTimeout(function () { window.location.href = "/App/Gis"; }, 1000); } else { showError("Error", data.sErrorMessage); btnRegister.prop("disabled", false); } }, error: function (jqXHR, textStatus) { if (jqXHR.status === 0) { showError("Error", "Connection problem"); } else { showError("Error", "Unknown problem"); } btnRegister.prop("disabled", false); } }); }); function onlyValidateRegisterForm() { $("input", "form").addClass("ignore"); $("input", "#registration-form").removeClass("ignore"); } function showErrorSignUpCaptchaValidation() { showWarning('', 'Nous devons nous assurer que vous n´êtes pas un robot. S´il vous plaît, effectuez les actions nécessaires dans le "captcha".'); $('#signUpRecaptcha').addClass('captcha-validation-err'); setTimeout(function () { $('#signUpRecaptcha').removeClass('captcha-validation-err'); }, 2000); } }); //# sourceMappingURL=Login.js.map