// ------------------------------------------------------- Start Code SMS $(document).ready(function () { $('#btnSmsReceiver').on("click", handleSmsReceiverClick); }); $('.codeInput').keyup(function (e) { if (this.value.length === this.maxLength) { let next = $(this).data('next'); $('#n' + next).focus(); $('#n' + next).select(); } //وقتی کد ورودی وارد شد، اتوماتیک ورود میشود if ($('#n0').val() && $('#n1').val() && $('#n2').val() && $('#n3').val() && $('#n4').val() && $('#n5').val()) { $('#submit').removeClass('disable'); confirmCode(); } }); $('#codeInput').on('keyup', function () { this.value = this.value.replace(/[^\d]/, ''); }); $(".codeInput").click(function () { $(this).select(); }); function handleSmsReceiverClick() { let password = $('#signupInputPassword'); let repeatPassword = $('#repeat_password'); checkValidationPassword(password.val(), repeatPassword.val()); if (valid) { if (password.val() === '' || repeatPassword.val() === '') { displayAlert('لطفاً هر دو فیلد رمز عبور را پر کنید'); password.addClass('errored'); repeatPassword.addClass('errored'); setTimeout(function () { password.removeClass('errored'); repeatPassword.removeClass('errored'); }, 3500); } else if (password.val() !== repeatPassword.val()) { repeatPassword.addClass('errored'); setTimeout(function () { repeatPassword.removeClass('errored'); }, 3500); displayAlert('رمز عبور و تکرار آن باید یکسان باشند'); } else { toggleLoading(true); $('#btnSmsReceiver').hide(); $('#sentCode').hide(); $('#form').hide(); sendVerifyCode(); } } } function sendVerifyCode() { $.ajax({ dataType: 'json', type: 'POST', url: sendSmsAjax, headers: { "RequestVerificationToken": antiForgeryToken }, success: function (response) { if (response.isSuccess) { startCodeTimer(); } else { toggleLoading(false); $('#btnSmsReceiver').show(); $('#form').show(); } }, error: function (response) { console.error('Error:', response); } }); } var timerInterval; function startCodeTimer() { resetOtpInput(); $('#codeDiv, #submit, #timerCount, .otp').show(); toggleLoading(false); $('#msg').hide(); $('#n0').focus(); var timer = "2:00"; if (timerInterval) { clearInterval(timerInterval); } timerInterval = setInterval(function () { const [minutes, seconds] = timer.split(':').map(Number); const updatedSeconds = seconds - 1; const updatedMinutes = updatedSeconds < 0 ? minutes - 1 : minutes; const displaySeconds = (updatedSeconds < 0 ? 59 : updatedSeconds).toString().padStart(2, '0'); if (updatedMinutes < 0) { clearInterval(timerInterval); timerInterval = null; } else { timer = `${updatedMinutes}:${displaySeconds}`; $('.countdown').text(timer); } if (timer === "0:00" && !$('#form').hasClass("showPassDiv")) { resetCodeEntry(); } }, 1000); } function resetCodeEntry() { $('#submit').addClass('disable'); $('#submit').hide(); resetOtpInput(); $('#btnSmsReceiver').show(); $('#sentCode').show(); toggleLoading(false); $('#timerCount, .otp').hide(); $('#msg').show(); } function confirmCode() { const code = Array.from({ length: 6 }, (_, i) => $(`#n${i}`).val()).join(''); if (code.length === 6) { toggleLoading(true); setTimeout(() => { $.ajax({ async: false, dataType: 'json', type: 'POST', url: checkCodeAjax, headers: { "RequestVerificationToken": antiForgeryToken }, data: { code }, success: handleCodeVerificationResponse, error: function (response) { console.error('Error:', response); } }); }, 1000); } else { displayAlert('کد وارد شده کمتر از 6 رقم است'); } } function handleCodeVerificationResponse(response) { toggleLoading(false); if (response.exist) { //$('#form').show().addClass("showPassDiv"); //$('#timerCount, .otp, #btn-login-code').hide(); $('#timerCount, .otp').hide(); $('#submit').show(); $('#msg').hide(); changePasswordCameraAccount(); } else { displayAlert('کد وارد شده صحیح نیست'); } } function resetOtpInput() { $('.codeInput').val(''); } function toggleLoading(isLoading) { $('.loading').toggle(isLoading); } function displayAlert(message) { $('.alert-msg').show().find('p').text(message); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); }, 3500); } // ------------------------------------------------------- Stop Code SMS var eyeShow = $('.eyeShow'); var eyeClose = $('.eyeClose'); var reEyeShow = $('.reEyeShow'); var reEyeClose = $('.reEyeClose'); $(document).ready(function () { eyeShow.show(); eyeClose.hide(); reEyeShow.show(); reEyeClose.hide(); }); $('#username, #signupInputPassword, #repeat_password').on('keyup', function () { if ($('#signupInputPassword').val() && $('#repeat_password').val() && $('#signupInputPassword').val() === $('#repeat_password').val()) { $('#next-step').removeClass('disable'); } else { $('#next-step').addClass('disable'); } }); $('#repeat_password').on('keyup', function () { if ($('#signupInputPassword').val() !== $('#repeat_password').val()) { $('#passwordErrorMessage').text('گذرواژه یکسان نیست'); } else { $('#passwordErrorMessage').text(''); } }); function passFunction() { var x = document.getElementById("signupInputPassword"); if (x.type === "password") { x.type = "text"; eyeShow.hide(); eyeClose.show(); } else { x.type = "password"; eyeShow.show(); eyeClose.hide(); } } function rePassFunction() { var x = document.getElementById("repeat_password"); if (x.type === "password") { x.type = "text"; reEyeShow.hide(); reEyeClose.show(); } else { x.type = "password"; reEyeShow.show(); reEyeClose.hide(); } } function passwordCheck(password) { if (password.length >= 8) strength += 1; if (password.match(/(?=.*[0-9])/)) strength += 1; if (password.match(/(?=.*[!,%,&,@,#,$,^,*,?,_,~,<,>,])/)) strength += 1; if (password.match(/(?=.*[A-Z])/)) strength += 1; displayBar(strength); } function displayBar(strength) { $(".password-strength-group").attr('data-strength', strength); } $("#signupInputPassword").keyup(function () { strength = 0; var password = $(this).val(); passwordCheck(password); }); function changePasswordCameraAccount() { var data = $('#create-form2').serialize(); $.ajax({ async: false, dataType: 'json', type: 'POST', url: saveCameraAccountPasswordChangeAjax, headers: { "RequestVerificationToken": antiForgeryToken }, data: data, success: function (response) { if (response.success) { clearInterval(timerInterval); $('.alert-success-msg').show(); $('.alert-success-msg p').text(response.message); setTimeout(function () { $('.alert-success-msg').hide(); $('.alert-success-msg p').text(''); }, 3500); $('#MainModal').modal('hide'); //window.location.reload(); } else { $('.alert-msg').show(); $('.alert-msg p').text(response.message); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); }, 3500); } }, error: function (err) { console.log(err); } }); } var valid = true; function checkValidationPassword(password, rePassword) { $.ajax({ async: false, dataType: 'json', type: 'GET', url: ajaxCameraValidation, headers: { "RequestVerificationToken": antiForgeryToken }, data: { 'password': password, 'rePassword': rePassword }, success: function (response) { if (response.success) { valid = true; } else { $('.alert-msg').show(); $('.alert-msg p').text(response.message); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); }, 3500); valid = false; } }, error: function (err) { console.log(err); valid = false; return false; } }); }