function checkLogin() { $.ajax({ type: "POST", url: "php/check_login.php", data: { }, success: function (res) { if(res == "unlogged") { openLoginSection(); auth_user = 0; } else { auth_user = 1; } } }); } function openLoginSection() { document.getElementById("login_page").style.display = 'block'; document.getElementById("open_login_page").click(); } function loginRequest() { $.post("php/auth.php", { accessoUtente: true, //prendo i dati inseriti e li invio a php email: $('input[name="email"]').val(), password: $('input[name="password"]').val() }, function (response) { //risposta da php console.log(response); //dati corretti if (response === "2") { //dati errati Swal.fire({ type: 'error', text: 'Email o password errati!' }); } else if (response === "3") { //dati errati Swal.fire({ type: 'error', text: 'Email o password errati!' }); } else { Swal.fire({ type: 'success', title: 'Login riuscito!', showConfirmButton: false, timer: 2000 }); document.getElementById("close-modal").click(); auth_user = 1; document.querySelector("#menu_main_username").innerHTML = response; location.reload(); } }); } function logoutRequest() { $.post("php/logout.php", {}, function () { auth_user = 0; location.reload(); }); } function openForgotSection() { document.getElementById("forgot_page").style.display = 'block'; document.getElementById("open_forgot_page").click(); /* var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#forgot-content").style.display="block"; document.querySelector("#forgot-content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/forgot.php"); xmlhttp.send(); */ } function sendForgotVerificationCode() { var email = document.querySelector('#forgot_email').value; $.ajax({ type: "POST", url: "php/forgot/check_email.php", data: { email : email }, success: function (res) { if (res == "ok") { $.ajax({ type: "POST", url: "php/forgot/send_forgot_verification_code.php", data: { email : email }, success: function (res) { if (res == "ok") { document.querySelector('#forgot_password_content').style.display="none"; document.querySelector('#otp_verification_content').style.display="block"; } else { Swal.fire( 'Errore!', 'Codice non inviato', 'error' ); } } }); } else { Swal.fire( 'Errore!', 'Email non trovata', 'error' ); } } }); } function checkForgotVerificationCode() { var email = document.querySelector('#forgot_email').value; var otp_num_1 = document.querySelector('#otp_num_1').value; var otp_num_2 = document.querySelector('#otp_num_2').value; var otp_num_3 = document.querySelector('#otp_num_3').value; var otp_num_4 = document.querySelector('#otp_num_4').value; $.ajax({ type: "POST", url: "php/forgot/check_forgot_verification_code.php", data: { otp_num_1 : otp_num_1, otp_num_2 : otp_num_2, otp_num_3 : otp_num_3, otp_num_4 : otp_num_4, email : email}, success: function (res) { if (res == "ok") { document.querySelector('#otp_verification_content').style.display="none"; openForgotPasswordReset(); } else { Swal.fire( 'Errore!', 'Codice non valido', 'error' ); } } }); } function openForgotPasswordReset() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#password_reset_content").innerHTML = this.responseText; document.querySelector("#password_reset_content").style.display="block"; } }; xmlhttp.open("GET", "php/forgot/password_reset_forgot_content.php"); xmlhttp.send(); } function changeForgotPassword() { var email = document.querySelector('#forgot_email').value; var new_password = document.querySelector("#new_pass").value; var repeat_new_password = document.querySelector("#repeat_new_pass").value; if(new_password == repeat_new_password) { if(new_password.length < 8) { Swal.fire( 'Errore!', 'La password deve essere di almeno 8 caratteri', 'error' ); } else { if(/\d/.test(new_password) == false) { Swal.fire( 'Errore!', 'La password deve contenere almeno un numero', 'error' ); } else { var special_char = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/; if(special_char.test(new_password) == false) { Swal.fire( 'Errore!', 'La password deve contenere almeno un carattere speciale', 'error' ); } else { $.ajax({ type: "POST", url: "php/forgot/change_forgot_password.php", data: { new_password : new_password, email : email}, success: function (res) { if (res == "ok") { Swal.fire( 'Password modificata!', 'La password รจ stata modificata con successo', 'success' ); location.reload(); } else { Swal.fire( 'Errore!', 'Password non cambiata', 'error' ); } } }); } } } } else { Swal.fire( 'Errore!', 'Le password non sono uguali', 'error' ); } } //Chiudere i messaggi d'errore function closeError(element_id) { document.querySelector('#' + element_id).style.display = 'none'; }