123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- function initLogin() {
- let reg_name, reg_email, reg_number, reg_pwd, reg_otp_email;
- let loginForm = $("#login_form");
- let registerForm = $("#register_form");
-
- // document.querySelector('#register_form .otp-input-group input.press').addEventListener("paste", function (p) {
- // var data = p.clipboardData.getData('text');
- // var dataLength = data.length;
-
- // for (var i = 0; i < dataLength; i++) {
- // var input = document.querySelector("#register_form .otp-input-group input[tabindex='" + (i + 1) + "']");
- // input.value = data.charAt(i);
- // if (input.value.length >= input.maxLength) {
- // var nextInput = document.querySelector("#register_form .otp-input-group input[tabindex='" + (i + 2) + "']");
- // if (nextInput) {
- // nextInput.focus();
- // }
- // }
- // }
- // p.preventDefault();
- // });
- // document.querySelectorAll('#register_form .otp-input-group input[type="text"]').forEach(function (input) {
- // input.addEventListener('keyup', function (e) {
- // if (this.value.length >= this.maxLength) {
- // if (e.keyCode !== 9 && e.keyCode !== 16) {
- // var tabIndex = this.tabIndex + 1;
- // document.querySelector("#register_form .otp-input-group input[tabindex='" + this.tabIndex + "']").value = this.value;
- // document.querySelector("#register_form .otp-input-group input[tabindex='" + tabIndex + "']").focus();
- // }
- // } else {
- // if (e.keyCode === 8) {
- // var tabIndex = this.tabIndex - 1;
- // document.querySelector("#register_form .otp-input-group input[tabindex='" + tabIndex + "']").focus();
- // }
- // }
- // });
- // });
-
- $('#register_form .otp-input-group input.press').on('paste', function (p) {
- var data = p.originalEvent.clipboardData.getData('text');
- var dataLength = data.length;
-
- for (var i = 0; i < dataLength; i++) {
- var input = $('#register_form .otp-input-group input[tabindex="' + (i + 1) + '"]');
- input.val(data.charAt(i));
- if (input.val().length >= input.attr('maxlength')) {
- var nextInput = $('#register_form .otp-input-group input[tabindex="' + (i + 2) + '"]');
- if (nextInput) {
- nextInput.focus();
- }
- }
- }
- p.preventDefault();
- });
-
- $('#register_form .otp-input-group input[type="text"]').on('keyup', function (e) {
- if ($(this).val().length >= $(this).attr('maxlength')) {
- if (e.keyCode !== 9 && e.keyCode !== 16) {
- var tabIndex = parseInt($(this).attr('tabindex')) + 1;
- $('#register_form .otp-input-group input[tabindex="' + $(this).attr('tabindex') + '"]').val($(this).val());
- $('#register_form .otp-input-group input[tabindex="' + tabIndex + '"]').focus();
- }
- } else {
- if (e.keyCode === 8) {
- var tabIndex = parseInt($(this).attr('tabindex')) - 1;
- $('#register_form .otp-input-group input[tabindex="' + tabIndex + '"]').focus();
- }
- }
- });
-
-
- loginForm.find("#User_Email,#User_password").keypress(function (e) {
- if (e.which == 13)
- document.getElementById("Login_btn").click();
-
- });
-
- $("#Login_btn").click(function () {
- loginForm.find(".loader-btn").show();
- $(this).hide();
- let userEmail = loginForm.find("#User_Email").val();
- let userPassword = loginForm.find("#User_password").val();
- let emailInput = loginForm.find(".email-login-inputgroup");
- let passwordInput = loginForm.find(".password-login-inputgroup");
- if (userEmail == "") {
- emailInput.find('#User_Email').addClass('is-invalid');
- emailInput.find('.form-floating').addClass('is-invalid');
- emailInput.find('.invalid-feedback').text('Please enter your email');
- loginForm.find(".loader-btn").hide();
- $(this).show();
-
- }
- if (userPassword == "") {
- passwordInput.find('#User_password').addClass('is-invalid');
- passwordInput.find('.form-floating').addClass('is-invalid');
- loginForm.find(".loader-btn").hide();
- $(this).show();
- }
- else {
- emailInput.find('#User_Email').removeClass('is-invalid');
- emailInput.find('.form-floating').removeClass('is-invalid');
- passwordInput.find('#User_password').removeClass('is-invalid');
- passwordInput.find('.form-floating').removeClass('is-invalid');
- if (validateEmail(userEmail)) {
- let port = SERVERNAME
- // let port = "http://localhost:3088";
- let url = `${port}/account/getuserbyphoneormail/${userEmail}/${userEmail}`;
- getDataStatAxios(url, userEmail);
- } else {
- loginForm.find(".loader-btn").hide();
- $(this).show();
- emailInput.find('#User_Email').addClass('is-invalid');
- emailInput.find('.form-floating').addClass('is-invalid');
- emailInput.find('.invalid-feedback').text('Please enter a valid email');
- }
- }
- });
-
- async function getDataStatAxios(url, userEmail) {
- const config = {
- url,
- method: "get",
- };
- let response = await axios(config);
- if (response.data.result == null) {
- $('.error-div').text(response.data.message);
- }
- else {
- let userEmail = $("#User_Email").val();
- let userPassword = $("#User_password").val();
- const loginPayload = {
- username: userEmail,
- Password: userPassword,
- UnibaseId: "",
- RememberMe: false,
- };
- const res = await postAPIService(
- `bizgaze/crm/webapi/crmuserlogin`,
- loginPayload
- );
- debugger;
- console.log(res);
- if (res.data.message == "200") {
- // Command: toastr["success"]("Logged in successfully")
- // toasterOpts();
- debugger;
- COOKIE_HELPER_ACTIONS.setCookie({
- token: res.data.result.sessionId,
- userid: res.data.result.userId,
- ...res.data.result
- })
- // setInitLoginLocal();
- // window.localStorage.setItem("Useremail", userEmail);
- //window.localStorage.setItem("Userpassword", userPassword);
- //window.localStorage.setItem("Isloggedin", true);
- const isCartAdded = localStorage.getItem(CART_ADD);
- if(isCartAdded){
- localStorage.removeItem(CART_ADD);
- window.location.href = `/selectdelivery.html`;
- return;
- }
- window.location.href = `/index.html`;
- } else {
- $("#empt_num").removeClass("d-none text-success").text(res.data.message).addClass('text-danger');
- $(".my_avatar").attr("href", "./login.html");
- }
- }
- }
-
- // this function will be triggered on new user registration
- async function userRegistration() {
- reg_form = $('#register_form');
- // reg_name = $("#User_Name").val();
- reg_email = reg_form.find("#User_Email").val();
- // reg_otp_email = $("#User_otp_Email").val();
- // reg_number = $("#user_number").val();
- reg_pwd = reg_form.find("#User_password").val();
- let userName = reg_email.split("@");
- let otpRes = null;
- const userRegistratioNPayload = {
- organizationtypeid: "2",
- organizationid: "0",
- contactid: "0",
- userid: "0",
- username: "0",
- users_phonenumber: "0",
- password: reg_pwd,
- users_emailaddress: "0",
- emailaddress: reg_email,
- contactname: userName[0],
- phonenumber: "0",
- branchid: "0",
- tenantname: "Anwi Systems",
- rolename: "Customer Admin",
- currencyid: "0",
- customerformuniqueid: "Bizgaze_Platform_Crm_RegisterCRMUser",
- };
- $('.spinner-border').removeClass('d-none');
- const res = await postAPIService(
- `bizgaze/crm/webapi/registercrmuser`,
- userRegistratioNPayload
- );
- console.log(res, "register");
- $('.spinner-border').addClass('d-none');
- if (res.data.message == "User Already Exists!") {
- $('.error-div').text('User Already Exists!');
- // $(".useralready_exist").removeClass("d-none");
- } else {
- }
-
- $("#proceed").click(async function () {
- let userEnterOtp = "";
- let userEmail = registerForm.find("#User_Email").val();
- $('.otp-input-group input').each(function () {
- let presVal = $(this).val();
- userEnterOtp += presVal;
- })
- console.log(userEnterOtp);
- debugger;
- const userotppayload = {
- email: userEmail,
- otpid: res.data.result.OtpId,
- userotp: userEnterOtp,
- };
- $('.spinner-border').removeClass('d-none');
- otpRes = await postAPIService(
- `bizgaze/crm/webapi/ValidateOtp`,
- userotppayload
- );
- $('.spinner-border').addClass('d-none');
- debugger;
- console.log(otpRes, "otp");
- const verifyotpStatus = otpRes.data.result;
- debugger;
- if (verifyotpStatus == "Otp verified successfully") {
- alert("Account created successfully");
- window.location.href = `/myaccount.html`;
- } else {
- alert("please enter valid otp");
- }
- });
- }
-
- // to validate password on keyup in password input field
- function passwordValidate(pswd) {
- if (pswd.length < 11) {
- $('#chck_length').removeClass('pswd_valid').addClass('pswd_invalid');
- } else {
- $('#chck_length').removeClass('pswd_invalid').addClass('pswd_valid');
- }
- // validate uppercase letter
- if (pswd.match(/[A-Z]/)) {
- $('#chck_capital').removeClass('pswd_invalid').addClass('pswd_valid');
- } else {
- $('#chck_capital').removeClass('pswd_valid').addClass('pswd_invalid');
- }
- //validate special letter
- if (pswd.match(/[!@#$%^&*]/)) {
- $('#chck_special').removeClass('pswd_invalid').addClass('pswd_valid');
- } else {
- $('#chck_special').removeClass('pswd_valid').addClass('pswd_invalid');
- }
- let pswdVal = $('#register_form #User_password').val();
- let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
- if (pswdVal.match(pattern)) {
- $('#pswd_info').hide()
- }
- else {
- $('#pswd_info').show()
- }
- //validate number
- if (pswd.match(/\d/)) {
- $('#chck_number').removeClass('pswd_invalid').addClass('pswd_valid');
- } else {
- $('#chck_number').removeClass('pswd_valid').addClass('pswd_invalid');
- }
-
- };
-
- //you have to use keyup, because keydown will not catch the currently entered value
- $('#register_form #User_password').keyup(function () {
- // set password variable
- var pswd = $(this).val();
- passwordValidate(pswd);
- }).focus(function () {
- let pswdVal = $('#register_form #User_password').val();
- let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
- if (pswdVal.match(pattern)) {
- $('#pswd_info').hide()
- }
- else {
- $('#pswd_info').show()
- }
- }).blur(function () {
- $('#pswd_info').hide();
- });
-
- // function to validate user entered email
- function validateEmail(userEmail) {
- var pattern =
- /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
- return $.trim(userEmail).match(pattern) ? true : false;
- }
-
- // function to validate user entered password
- function validatepassword(userPassword) {
- var pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
- return $.trim(userPassword).match(pattern) ? true : false;
- }
-
- registerForm.find("#User_Email,#User_password").keypress(function (e) {
- if (e.which == 13)
- document.getElementById("register_btn").click();
-
- });
-
- // this will be triggered on clicking continue in signup form
- $("#register_btn").click(function () {
- registerForm.find(".loader-btn").show();
- $(this).hide();
- let userEmail = registerForm.find("#User_Email").val();
- let userPassword = registerForm.find("#User_password").val();
- let emailInput = registerForm.find(".email-login-inputgroup");
- let passwordInput = registerForm.find(".password-login-inputgroup");
- if (userEmail == "") {
- emailInput.find('#User_Email').addClass('is-invalid');
- emailInput.find('.form-floating').addClass('is-invalid');
- emailInput.find('.invalid-feedback').text('Please enter your email');
- registerForm.find(".loader-btn").hide();
- $(this).show();
- }
- if (userPassword == "") {
- passwordInput.find('#User_password').addClass('is-invalid');
- passwordInput.find('.form-floating').addClass('is-invalid');
- registerForm.find(".loader-btn").hide();
- $(this).show();
- }
- else {
- emailInput.find('#User_Email').removeClass('is-invalid');
- emailInput.find('.form-floating').removeClass('is-invalid');
- passwordInput.find('#User_password').removeClass('is-invalid');
- passwordInput.find('.form-floating').removeClass('is-invalid');
- if (validateEmail(userEmail)) {
- $('#register_form .email-password-group').hide();
- $('#register_form .otp-input-group').show();
- $('#register_form .otp-input-group .otp-sent-email').text(userEmail);
- userRegistration();
- } else {
- emailInput.find('#User_Email').addClass('is-invalid');
- emailInput.find('.form-floating').addClass('is-invalid');
- emailInput.find('.invalid-feedback').text('Please enter a valid email');
- registerForm.find(".loader-btn").hide();
- $(this).show();
- }
- }
- });
-
- $('#forgotPassword').click(function () {
- $('.login-email-password-div').hide();
- $('.login-forgot-passsword-div').show();
- })
-
- function toasterOpts() {
- toastr.options = {
- "closeButton": true,
- "debug": false,
- "newestOnTop": true,
- "progressBar": true,
- "positionClass": "toast-top-center",
- "preventDuplicates": true,
- "showDuration": "300",
- "hideDuration": "1000",
- "timeOut": "3000",
- "extendedTimeOut": "1000",
- "showEasing": "swing",
- "hideEasing": "linear",
- "showMethod": "fadeIn",
- "hideMethod": "fadeOut"
- }
- }
- }
-
- initLogin();
|