function openProfile() { if (auth_user == 1) { document.getElementById("profile").style.display = 'block'; document.getElementById("open_profile").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#profile_content").innerHTML = this.responseText; newTickets(); } }; xmlhttp.open("GET", "php/profile/profile_content.php"); xmlhttp.send(); } else { openLoginSection(); } } function sendVerificationCode() { $.ajax({ type: "POST", url: "php/profile/send_verification_code.php", data: { }, success: function (res) { if (res == "ok") { document.querySelector('#password_reset_content').style.display="none"; document.querySelector('#otp_verification_content').style.display="block"; } else { Swal.fire( 'Errore!', 'Mail non inviata.', 'error' ); } } }); } function checkVerificationCode() { 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/profile/check_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}, success: function (res) { if (res == "ok") { Swal.fire( 'Codice corretto!', 'Cambio password consentito', 'success' ); document.querySelector('#otp_verification_content').style.display="none"; openPasswordReset(); } else { Swal.fire( 'Errore!', 'Codice non valido', 'error' ); } } }); } function openPasswordReset() { 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/profile/password_reset_content.php"); xmlhttp.send(); } function changePassword() { 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/profile/change_password.php", data: { new_password : new_password}, success: function (res) { if (res == "ok") { Swal.fire( 'Password modificata!', 'La password รจ stata modificata con successo', 'success' ); setTimeout(() => { logoutRequest(); }, 2000); } else { Swal.fire( 'Errore!', 'Password non cambiata', 'error' ); } } }); } } } } else { Swal.fire( 'Errore!', 'Le password non sono uguali', 'error' ); } }