HEX
Server: LiteSpeed
System: Linux linux31.centraldnserver.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: salamatk (1501)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open
Upload Files
File: /home/salamatk/takarzan.ir/wp-content/themes/xts-luman/woocommerce/myaccount/js/script.js
$(document).ready(function () {
  var mobile;

  toastr.options = {
    closeButton: false,
    debug: false,
    newestOnTop: true,
    progressBar: true,
    positionClass: "toast-bottom-left",
    preventDuplicates: true,
    onclick: null,
    showDuration: "300",
    hideDuration: "1000",
    timeOut: "5000",
    extendedTimeOut: "1000",
    showEasing: "swing",
    hideEasing: "linear",
    showMethod: "fadeIn",
    hideMethod: "fadeOut",
  };

  // نمایش صفحه مورد نظر و مخفی کردن بقیه صفحات
  function showPage(pageId) {
    $(".luman-form-page").hide();
    $("#" + pageId).show();
  }

  showPage("luman-page-phone");

  $("#luman-btn-continue-phone").click(function () {
    const $form = $(".luman-form-card");
    mobile = $("input#luman-phone-number").val() ?? "";

    const reCAPTCHA_v = $form.attr("data-type");
    let recaptchaToken = "";

    if (reCAPTCHA_v === "v2") {
      recaptchaToken = grecaptcha.getResponse();

      if (!recaptchaToken) {
        toastr.error("لطفا کپچا را کامل کنید!");
        return;
      }
    }

    if (reCAPTCHA_v === "v3") {
      recaptchaToken = $(document).find("#recaptchaResponse").val();
    }

    if (mobile === "") {
      toastr.error("لطفا شماره موبایل خود را وارد کنید!");
      return;
    }

    if (mobile.length > 11) {
      toastr.error("شماره موبایل وارد شده معتبر نمی باشد!");
      return;
    }

    $form.addClass("loading");

    $.ajax({
      url: luman_ajax_object.ajaxurl,
      type: "POST",
      data: {
        action: "luman_plus_login_user",
        mobile: mobile,
        recaptcha_token: recaptchaToken,
      },
      success: function (response) {
        $form.removeClass("loading");

        if (response.success) {
          if (
            response.data.action === "register" ||
            response.data.action === "loginByOTP"
          ) {
            showPage("luman-page-otp");
            startOtpTimer(response.data.threshold);

            $(".luman-otp-input").val("");
            $(".luman-otp-input:first").focus();
          } else {
            showPage("luman-page-password-login");
          }
        } else {
          toastr.warning(response.data.message);
        }
      },
    });
  });

  $("#luman-btn-back-otp").click(function () {
    stopOtpTimer();
    showPage("luman-page-phone");
  });

  $("#luman-btn-password-login-from-otp").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    setTimeout(() => {
      stopOtpTimer();
      showPage("luman-page-password-login");
      $form.removeClass("loading");
    }, 3000);
  });

  $("#luman-btn-back-password-login").click(function () {
    showPage("luman-page-phone");
  });

  $("#luman-btn-forgot-password").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    setTimeout(() => {
      showPage("luman-page-forgot-password");
      $form.removeClass("loading");
    }, 1500);
  });

  $("#luman-btn-back-forgot-password").click(function () {
    showPage("luman-page-password-login");
  });

  $("#luman-btn-send-reset-link").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    const contact = $("input#luman-forgot-password-contact").val().trim();

    if (contact.length > 0) {
      $.ajax({
        url: luman_ajax_object.ajaxurl,
        type: "POST",
        data: {
          action: "luman_plus_forgot_password",
          contact: contact,
        },
        success: function (response) {
          $form.removeClass("loading");

          if (response.success) {
            showPage("luman-page-reset-password");
            $(
              "#luman-new-password, #luman-confirm-new-password, #luman-reset-code"
            ).val("");
            updatePasswordStrengthBar(0);
            $form.removeClass("loading");
          } else {
            toastr.warning(response.data.message);
          }
        },
        error: function () {
          $form.removeClass("loading");
          toastr.error("خطا در ارتباط با سرور.");
        },
      });
    } else {
      toastr.error("لطفا ایمیل یا شماره موبایل خود را وارد کنید.");
      $form.removeClass("loading");
    }
  });

  $("#luman-btn-back-reset-password").click(function () {
    showPage("luman-page-forgot-password");
  });

  let otpTimerInterval;

  // شروع و مدیریت تایمر شمارش معکوس کد تایید
  function startOtpTimer(durationInSeconds) {
    let timer = durationInSeconds;
    const timerDisplay = $("#luman-otp-timer");
    const resendButton = $("#luman-btn-resend-otp");

    $("#luman-otp-timer-value").text(formatTime(timer));
    timerDisplay.show();
    resendButton.hide();

    if (otpTimerInterval) {
      clearInterval(otpTimerInterval);
    }

    otpTimerInterval = setInterval(function () {
      timer--;
      $("#luman-otp-timer-value").text(formatTime(timer));

      if (timer <= 0) {
        stopOtpTimer();
        timerDisplay.hide();
        resendButton.show();
      }
    }, 1000);
  }

  // توقف تایمر کد تایید
  function stopOtpTimer() {
    clearInterval(otpTimerInterval);
  }

  // تبدیل ثانیه به فرمت دقیقه:ثانیه
  function formatTime(seconds) {
    const minutes = Math.floor(seconds / 60);
    const remainingSeconds = seconds % 60;
    const formattedSeconds =
      remainingSeconds < 10 ? "0" + remainingSeconds : remainingSeconds;
    return minutes + ":" + formattedSeconds;
  }

  $("#luman-btn-resend-otp").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    $.ajax({
      url: luman_ajax_object.ajaxurl,
      type: "POST",
      data: {
        action: "luman_plus_otp_code_try_again",
      },
      success: function (response) {
        $form.removeClass("loading");

        if (response.success) {
          startOtpTimer(response.data.threshold);
          $(".luman-otp-input").val("");
          $(".luman-otp-input:first").focus();
        } else {
          toastr.warning(response.data.message);
        }
      },
      error: function () {
        $form.removeClass("loading");
        toastr.error("خطا در ارتباط با سرور.");
      },
    });
  });

  $(".luman-otp-input-container").on("input", ".luman-otp-input", function (e) {
    const $this = $(this);
    const maxLength = parseInt($this.attr("maxlength"));
    const currentLength = $this.val().length;

    if (
      currentLength >= maxLength &&
      e.originalEvent.inputType !== "deleteContentBackward"
    ) {
      const $nextInput = $this.next(".luman-otp-input");
      if ($nextInput.length) {
        $nextInput.focus();
      } else {
        $this.blur();
        const otpCode = $(".luman-otp-input")
          .map(function () {
            return $(this).val();
          })
          .get()
          .join("");
        if (otpCode.length > 0) {
          const $form = $(".luman-form-card");
          $form.addClass("loading");
          $.ajax({
            url: luman_ajax_object.ajaxurl,
            type: "POST",
            data: {
              action: "luman_plus_verify_otp",
              verify_code: otpCode,
            },
            success: function (response) {
              $form.removeClass("loading");

              if (response.success) {
                if (response.data.action !== "login") {
                  showPage("luman-page-register");
                } else {
                  window.location.href = response.data.redirect;
                }
              } else {
                toastr.warning(response.data.message);
              }
            },
          });
        }
      }
    }
  });

  $(".luman-otp-input-container").on(
    "keydown",
    ".luman-otp-input",
    function (e) {
      const $this = $(this);
      const currentLength = $this.val().length;

      if (e.key === "Backspace" && currentLength === 0) {
        const $prevInput = $this.prev(".luman-otp-input");
        if ($prevInput.length) {
          $prevInput.focus();
        }
      }
    }
  );

  // بررسی قدرت رمز عبور با استفاده از zxcvbn یا معیارهای پایه
  function checkPasswordStrength(password) {
    if (typeof zxcvbn === "undefined") {
      console.warn("zxcvbn library not loaded. Using basic strength check.");
      let strength = 0;
      if (password.length > 7) strength++;
      if (password.match(/[a-z]/)) strength++;
      if (password.match(/[A-Z]/)) strength++;
      if (password.match(/[0-9]/)) strength++;
      if (password.match(/[^a-zA-Z0-9]/)) strength++;
      return strength;
    } else {
      const result = zxcvbn(password);
      return result.score + 1;
    }
  }

  // بروزرسانی نوار نمایش قدرت رمز عبور
  function updatePasswordStrengthBar(strength) {
    const $bar = $(".luman-password-strength-bar .luman-strength-bar");
    const $strengthLevelText = $(".luman-strength-level");

    let width = (strength / 5) * 100;
    let color = "#e74c3c";
    let levelText = "آسان";

    if (strength > 1) {
      color = "#f39c12";
      levelText = "متوسط";
    }
    if (strength > 2) {
      color = "#f1c40f";
      levelText = "متوسط";
    }
    if (strength > 3) {
      color = "#2ecc71";
      levelText = "قوی";
    }
    if (strength > 4) {
      color = "#1abc9c";
      levelText = "قوی";
    }

    $bar.css({
      width: width + "%",
      backgroundColor: color,
    });
    $strengthLevelText.text(levelText).css("color", color);
  }

  $("#luman-password, #luman-new-password").on("input", function () {
    const password = $(this).val();
    const strength = checkPasswordStrength(password);
    updatePasswordStrengthBar(strength);
  });

  $(".luman-btn-generate-password").click(function () {
    const generatedPassword = generateStrongPassword(14);

    const $currentPage = $(".luman-form-page:visible");

    if ($currentPage.attr("id") === "luman-page-reset-password") {
      $("#luman-new-password, #luman-confirm-new-password").val(
        generatedPassword
      );
      $("#luman-new-password").trigger("input");
    } else if ($currentPage.attr("id") === "luman-page-register") {
      $("#luman-password").val(generatedPassword).trigger("input");
    } else {
      console.error("Generate password button clicked on an unexpected page.");
    }
  });

  // تولید رمز عبور قوی و تصادفی
  function generateStrongPassword(length) {
    const lower = "abcdefghijklmnopqrstuvwxyz";
    const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const numbers = "0123456789";
    const symbols = "!@#$%^&*()_+[]{}";
    const allChars = lower + upper + numbers + symbols;

    let password = "";
    password += lower.charAt(Math.floor(Math.random() * lower.length));
    password += upper.charAt(Math.floor(Math.random() * upper.length));
    password += numbers.charAt(Math.floor(Math.random() * numbers.length));
    password += symbols.charAt(Math.floor(Math.random() * symbols.length));

    for (let i = password.length; i < length; i++) {
      password += allChars.charAt(Math.floor(Math.random() * allChars.length));
    }

    password = password
      .split("")
      .sort(function () {
        return 0.5 - Math.random();
      })
      .join("");

    return password;
  }

  $("#luman-btn-otp-continue").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    const otpCode = $(".luman-otp-input")
      .map(function () {
        return $(this).val();
      })
      .get()
      .join("");

    $.ajax({
      url: luman_ajax_object.ajaxurl,
      type: "POST",
      data: {
        action: "luman_plus_verify_otp",
        verify_code: otpCode,
      },
      success: function (response) {
        $form.removeClass("loading");

        if (response.success) {
          if (response.data.action !== "login") {
            showPage("luman-page-register");
          } else {
            window.location.href = response.data.redirect;
          }
        } else {
          toastr.warning(response.data.message);
        }
      },
    });
  });

  $("#luman-btn-register-submit").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    const fullName = $("#luman-full-name").val().trim();
    const email = $("#luman-email").val();
    const password = $("#luman-password").val();

    const nameParts = fullName.split(" ");
    const firstName = nameParts[0] ?? "";
    const lastName = nameParts.slice(1).join(" ") ?? "";

    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

    if (!firstName || !lastName || !email || !password) {
      toastr.error("لطفا تمام فیلدها را پر کنید.");
      $form.removeClass("loading");
      return;
    }

    if (!emailRegex.test(email)) {
      toastr.warning("ایمیل وارد شده معتبر نیست.");
      $form.removeClass("loading");
      return;
    }

    $.ajax({
      url: luman_ajax_object.ajaxurl,
      type: "POST",
      data: {
        action: "luman_plus_register_user",
        first_name: firstName,
        last_name: lastName,
        user_email: email,
        user_password: password,
      },
      success: function (response) {
        $form.removeClass("loading");
        if (response.success) {
          toastr.success(response.data.message);
          setTimeout(() => {
            window.location.href = response.data.redirect;
          }, 1500);
        }
        if (!response.success) {
          toastr.warning(response.data);
        }
      },
      error: function () {
        $form.removeClass("loading");
        toastr.error("خطا در ارتباط با سرور.");
      },
    });
  });

  $("#luman-btn-password-login-submit").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    const password = $("#luman-password-login").val();

    $.ajax({
      url: luman_ajax_object.ajaxurl,
      type: "POST",
      data: {
        action: "luman_plus_user_login_in_dashboard",
        password: password,
      },
      success: function (response) {
        $form.removeClass("loading");

        if (response.success) {
          toastr.success(response.data.message);
          window.location.href = response.data.redirect;
        } else {
          toastr.warning(response.data.message ?? "خطایی رخ داده است.");
        }
      },
      error: function () {
        toastr.error("ارتباط با سرور برقرار نشد.");
      },
    });
  });

  $("#luman-btn-otp-login-from-password").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    $.ajax({
      url: luman_ajax_object.ajaxurl,
      type: "POST",
      data: {
        action: "luman_plus_login_otp_code",
      },
      success: function (response) {
        $form.removeClass("loading");

        if (response.success) {
          showPage("luman-page-otp");
          startOtpTimer(response.data.threshold);

          $(".luman-otp-input").val("");
          $(".luman-otp-input:first").focus();
        } else {
          showPage("luman-page-password-login");
          toastr.warning(response.data.message);
        }
      },
    });
  });

  $("#luman-btn-change-password").click(function () {
    const $form = $(".luman-form-card");
    $form.addClass("loading");

    const resetCode = $("#luman-reset-code").val();
    const newPassword = $("#luman-new-password").val();
    const confirmNewPassword = $("#luman-confirm-new-password").val();

    if (resetCode && newPassword && confirmNewPassword) {
      if (newPassword === confirmNewPassword) {
        const strength = checkPasswordStrength(newPassword);
        if (strength < 3) {
          alert("رمز عبور جدید به اندازه کافی قوی نیست.");
          $form.removeClass("loading");
          return;
        }

        $.ajax({
          url: luman_ajax_object.ajaxurl,
          type: "POST",
          data: {
            action: "luman_plus_reset_password",
            otp_code: resetCode,
            new_password: newPassword,
            confirmed_password: confirmNewPassword,
          },
          success: function (response) {
            $form.removeClass("loading");
            if (response.success) {
              showPage("luman-page-password-login");
              toastr.success(response.data.message);
            } else {
              toastr.warning(response.data.message);
            }
          },
        });
      } else {
        alert("رمز عبور جدید و تکرار آن مطابقت ندارند.");
        $form.removeClass("loading");
      }
    } else {
      alert("لطفا تمام فیلدها را پر کنید.");
      $form.removeClass("loading");
    }
  });

  $(".password-toggle-icon").click(function () {
    const $this = $(this);
    // اگر آیکن داخل label یا div است، نزدیک‌ترین input را پیدا کن
    let $passwordInput = $this.siblings(
      'input[type="password"], input[type="text"]'
    );
    if ($passwordInput.length === 0) {
      $passwordInput = $this
        .parent()
        .find('input[type="password"], input[type="text"]');
    }
    const inputType = $passwordInput.attr("type");

    // مسیر آیکن‌ها
    let eyeIcon = "/woocommerce/myaccount/icons/eye.svg";
    let eyeSlashIcon = "/woocommerce/myaccount/icons/eye-slash.svg";
    let iconSrc = "";
    if (typeof xtsThemeVars !== "undefined" && xtsThemeVars.themeUrl) {
      // حالت ایده‌آل: مقداردهی توسط PHP
      if (inputType === "password") {
        $passwordInput.attr("type", "text");
        iconSrc = xtsThemeVars.themeUrl + eyeSlashIcon;
        $this.attr("alt", "Hide Password");
      } else {
        $passwordInput.attr("type", "password");
        iconSrc = xtsThemeVars.themeUrl + eyeIcon;
        $this.attr("alt", "Show Password");
      }
    } else {
      if (inputType === "password") {
        $passwordInput.attr("type", "text");
        iconSrc = "../wp-content/themes/xts-luman/woocommerce/myaccount/icons/eye-slash.svg";
        $this.attr("alt", "Hide Password");
      } else {
        $passwordInput.attr("type", "password");
        iconSrc = "../wp-content/themes/xts-luman/woocommerce/myaccount/icons/eye.svg";
        $this.attr("alt", "Show Password");
      }
    }
    $this.attr("src", iconSrc);
  });
});