336 lines
9.4 KiB
JavaScript
336 lines
9.4 KiB
JavaScript
// ------------------------------------------------------- Start Code SMS
|
||
$(document).ready(function () {
|
||
$('#btnSmsReceiver').on("click", handleSmsReceiverClick);
|
||
|
||
$("#phone_number").on("input", function () {
|
||
this.value = this.value.replace(/[^0-9]/g, '');
|
||
|
||
if (this.value.length > 11) {
|
||
this.value = this.value.slice(0, 11);
|
||
}
|
||
});
|
||
});
|
||
|
||
$('.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() {
|
||
var phoneNumber = $("#phone_number");
|
||
|
||
checkValidPhoneNumberAndPassword($("#accountId").val(), $("#phone_number").val(), $("#signupInputPassword").val(), $("#repeat_password").val());
|
||
|
||
if (valid) {
|
||
if (phoneNumber.val().length > 0 && phoneNumber.val().length !== 11) {
|
||
displayAlert('شماره تماس باید ۱۱ رقم باشد');
|
||
phoneNumber.addClass('errored');
|
||
setTimeout(function () {
|
||
phoneNumber.removeClass('errored');
|
||
}, 3500);
|
||
return false;
|
||
} 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').hide();
|
||
$('#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();
|
||
changeEditAccount();
|
||
} 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
|
||
|
||
$(document).ready(function () {
|
||
var eyeShow = $('.eyeShow');
|
||
var eyeClose = $('.eyeClose');
|
||
var reEyeShow = $('.reEyeShow');
|
||
var reEyeClose = $('.reEyeClose');
|
||
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 changeEditAccount() {
|
||
var data = $('#edit-form').serialize();
|
||
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: saveEditAccountAjax,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
data: data,
|
||
success: function (response) {
|
||
if (response.success) {
|
||
|
||
clearInterval(timerInterval);
|
||
|
||
if ($("#phone_number").val().length > 0) {
|
||
$('#profileMobileNumber').text($("#phone_number").val());
|
||
$('#mobileNumber').text($("#phone_number").val());
|
||
}
|
||
|
||
$('.alert-success-msg').show();
|
||
$('.alert-success-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
$('.alert-success-msg').hide();
|
||
$('.alert-success-msg p').text('');
|
||
}, 3500);
|
||
|
||
loadDataEmployeeSubAccountAjax(0);
|
||
$('#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 checkValidPhoneNumberAndPassword(id, phone, password, rePassword) {
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: ajaxCheckValidAccount,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
data: { 'accountId': Number(id), 'phoneNumber': phone, '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;
|
||
}
|
||
});
|
||
} |