설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

login_11.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. function initLogin() {
  2. let reg_name, reg_email, reg_number, reg_pwd, reg_otp_email;
  3. let loginForm = $("#login_form");
  4. let registerForm = $("#register_form");
  5. // document.querySelector('#register_form .otp-input-group input.press').addEventListener("paste", function (p) {
  6. // var data = p.clipboardData.getData('text');
  7. // var dataLength = data.length;
  8. // for (var i = 0; i < dataLength; i++) {
  9. // var input = document.querySelector("#register_form .otp-input-group input[tabindex='" + (i + 1) + "']");
  10. // input.value = data.charAt(i);
  11. // if (input.value.length >= input.maxLength) {
  12. // var nextInput = document.querySelector("#register_form .otp-input-group input[tabindex='" + (i + 2) + "']");
  13. // if (nextInput) {
  14. // nextInput.focus();
  15. // }
  16. // }
  17. // }
  18. // p.preventDefault();
  19. // });
  20. // document.querySelectorAll('#register_form .otp-input-group input[type="text"]').forEach(function (input) {
  21. // input.addEventListener('keyup', function (e) {
  22. // if (this.value.length >= this.maxLength) {
  23. // if (e.keyCode !== 9 && e.keyCode !== 16) {
  24. // var tabIndex = this.tabIndex + 1;
  25. // document.querySelector("#register_form .otp-input-group input[tabindex='" + this.tabIndex + "']").value = this.value;
  26. // document.querySelector("#register_form .otp-input-group input[tabindex='" + tabIndex + "']").focus();
  27. // }
  28. // } else {
  29. // if (e.keyCode === 8) {
  30. // var tabIndex = this.tabIndex - 1;
  31. // document.querySelector("#register_form .otp-input-group input[tabindex='" + tabIndex + "']").focus();
  32. // }
  33. // }
  34. // });
  35. // });
  36. $('#register_form .otp-input-group input.press').on('paste', function (p) {
  37. var data = p.originalEvent.clipboardData.getData('text');
  38. var dataLength = data.length;
  39. for (var i = 0; i < dataLength; i++) {
  40. var input = $('#register_form .otp-input-group input[tabindex="' + (i + 1) + '"]');
  41. input.val(data.charAt(i));
  42. if (input.val().length >= input.attr('maxlength')) {
  43. var nextInput = $('#register_form .otp-input-group input[tabindex="' + (i + 2) + '"]');
  44. if (nextInput) {
  45. nextInput.focus();
  46. }
  47. }
  48. }
  49. p.preventDefault();
  50. });
  51. $('#register_form .otp-input-group input[type="text"]').on('keyup', function (e) {
  52. if ($(this).val().length >= $(this).attr('maxlength')) {
  53. if (e.keyCode !== 9 && e.keyCode !== 16) {
  54. var tabIndex = parseInt($(this).attr('tabindex')) + 1;
  55. $('#register_form .otp-input-group input[tabindex="' + $(this).attr('tabindex') + '"]').val($(this).val());
  56. $('#register_form .otp-input-group input[tabindex="' + tabIndex + '"]').focus();
  57. }
  58. } else {
  59. if (e.keyCode === 8) {
  60. var tabIndex = parseInt($(this).attr('tabindex')) - 1;
  61. $('#register_form .otp-input-group input[tabindex="' + tabIndex + '"]').focus();
  62. }
  63. }
  64. });
  65. loginForm.find("#User_Email,#User_password").keypress(function (e) {
  66. if (e.which == 13)
  67. document.getElementById("Login_btn").click();
  68. });
  69. $("#Login_btn").click(function () {
  70. loginForm.find(".loader-btn").show();
  71. $(this).hide();
  72. let userEmail = loginForm.find("#User_Email").val();
  73. let userPassword = loginForm.find("#User_password").val();
  74. let emailInput = loginForm.find(".email-login-inputgroup");
  75. let passwordInput = loginForm.find(".password-login-inputgroup");
  76. if (userEmail == "") {
  77. emailInput.find('#User_Email').addClass('is-invalid');
  78. emailInput.find('.form-floating').addClass('is-invalid');
  79. emailInput.find('.invalid-feedback').text('Please enter your email');
  80. loginForm.find(".loader-btn").hide();
  81. $(this).show();
  82. }
  83. if (userPassword == "") {
  84. passwordInput.find('#User_password').addClass('is-invalid');
  85. passwordInput.find('.form-floating').addClass('is-invalid');
  86. loginForm.find(".loader-btn").hide();
  87. $(this).show();
  88. }
  89. else {
  90. emailInput.find('#User_Email').removeClass('is-invalid');
  91. emailInput.find('.form-floating').removeClass('is-invalid');
  92. passwordInput.find('#User_password').removeClass('is-invalid');
  93. passwordInput.find('.form-floating').removeClass('is-invalid');
  94. if (validateEmail(userEmail)) {
  95. let port = SERVERNAME
  96. // let port = "http://localhost:3088";
  97. let url = `${port}/account/getuserbyphoneormail/${userEmail}/${userEmail}`;
  98. getDataStatAxios(url, userEmail);
  99. } else {
  100. loginForm.find(".loader-btn").hide();
  101. $(this).show();
  102. emailInput.find('#User_Email').addClass('is-invalid');
  103. emailInput.find('.form-floating').addClass('is-invalid');
  104. emailInput.find('.invalid-feedback').text('Please enter a valid email');
  105. }
  106. }
  107. });
  108. async function getDataStatAxios(url, userEmail) {
  109. const config = {
  110. url,
  111. method: "get",
  112. };
  113. let response = await axios(config);
  114. if (response.data.result == null) {
  115. $('.error-div').text(response.data.message);
  116. }
  117. else {
  118. let userEmail = $("#User_Email").val();
  119. let userPassword = $("#User_password").val();
  120. const loginPayload = {
  121. username: userEmail,
  122. Password: userPassword,
  123. UnibaseId: "",
  124. RememberMe: false,
  125. };
  126. const res = await postAPIService(
  127. `bizgaze/crm/webapi/crmuserlogin`,
  128. loginPayload
  129. );
  130. debugger;
  131. console.log(res);
  132. if (res.data.message == "200") {
  133. // Command: toastr["success"]("Logged in successfully")
  134. // toasterOpts();
  135. debugger;
  136. COOKIE_HELPER_ACTIONS.setCookie({
  137. token: res.data.result.sessionId,
  138. userid: res.data.result.userId,
  139. ...res.data.result
  140. })
  141. // setInitLoginLocal();
  142. // window.localStorage.setItem("Useremail", userEmail);
  143. //window.localStorage.setItem("Userpassword", userPassword);
  144. //window.localStorage.setItem("Isloggedin", true);
  145. const isCartAdded = localStorage.getItem(CART_ADD);
  146. if(isCartAdded){
  147. localStorage.removeItem(CART_ADD);
  148. window.location.href = `/selectdelivery.html`;
  149. return;
  150. }
  151. window.location.href = `/index.html`;
  152. } else {
  153. $("#empt_num").removeClass("d-none text-success").text(res.data.message).addClass('text-danger');
  154. $(".my_avatar").attr("href", "./login.html");
  155. }
  156. }
  157. }
  158. // this function will be triggered on new user registration
  159. async function userRegistration() {
  160. reg_form = $('#register_form');
  161. // reg_name = $("#User_Name").val();
  162. reg_email = reg_form.find("#User_Email").val();
  163. // reg_otp_email = $("#User_otp_Email").val();
  164. // reg_number = $("#user_number").val();
  165. reg_pwd = reg_form.find("#User_password").val();
  166. let userName = reg_email.split("@");
  167. let otpRes = null;
  168. const userRegistratioNPayload = {
  169. organizationtypeid: "2",
  170. organizationid: "0",
  171. contactid: "0",
  172. userid: "0",
  173. username: "0",
  174. users_phonenumber: "0",
  175. password: reg_pwd,
  176. users_emailaddress: "0",
  177. emailaddress: reg_email,
  178. contactname: userName[0],
  179. phonenumber: "0",
  180. branchid: "0",
  181. tenantname: "Anwi Systems",
  182. rolename: "Customer Admin",
  183. currencyid: "0",
  184. customerformuniqueid: "Bizgaze_Platform_Crm_RegisterCRMUser",
  185. };
  186. $('.spinner-border').removeClass('d-none');
  187. const res = await postAPIService(
  188. `bizgaze/crm/webapi/registercrmuser`,
  189. userRegistratioNPayload
  190. );
  191. console.log(res, "register");
  192. $('.spinner-border').addClass('d-none');
  193. if (res.data.message == "User Already Exists!") {
  194. $('.error-div').text('User Already Exists!');
  195. // $(".useralready_exist").removeClass("d-none");
  196. } else {
  197. }
  198. $("#proceed").click(async function () {
  199. let userEnterOtp = "";
  200. let userEmail = registerForm.find("#User_Email").val();
  201. $('.otp-input-group input').each(function () {
  202. let presVal = $(this).val();
  203. userEnterOtp += presVal;
  204. })
  205. console.log(userEnterOtp);
  206. debugger;
  207. const userotppayload = {
  208. email: userEmail,
  209. otpid: res.data.result.OtpId,
  210. userotp: userEnterOtp,
  211. };
  212. $('.spinner-border').removeClass('d-none');
  213. otpRes = await postAPIService(
  214. `bizgaze/crm/webapi/ValidateOtp`,
  215. userotppayload
  216. );
  217. $('.spinner-border').addClass('d-none');
  218. debugger;
  219. console.log(otpRes, "otp");
  220. const verifyotpStatus = otpRes.data.result;
  221. debugger;
  222. if (verifyotpStatus == "Otp verified successfully") {
  223. alert("Account created successfully");
  224. window.location.href = `/myaccount.html`;
  225. } else {
  226. alert("please enter valid otp");
  227. }
  228. });
  229. }
  230. // to validate password on keyup in password input field
  231. function passwordValidate(pswd) {
  232. if (pswd.length < 11) {
  233. $('#chck_length').removeClass('pswd_valid').addClass('pswd_invalid');
  234. } else {
  235. $('#chck_length').removeClass('pswd_invalid').addClass('pswd_valid');
  236. }
  237. // validate uppercase letter
  238. if (pswd.match(/[A-Z]/)) {
  239. $('#chck_capital').removeClass('pswd_invalid').addClass('pswd_valid');
  240. } else {
  241. $('#chck_capital').removeClass('pswd_valid').addClass('pswd_invalid');
  242. }
  243. //validate special letter
  244. if (pswd.match(/[!@#$%^&*]/)) {
  245. $('#chck_special').removeClass('pswd_invalid').addClass('pswd_valid');
  246. } else {
  247. $('#chck_special').removeClass('pswd_valid').addClass('pswd_invalid');
  248. }
  249. let pswdVal = $('#register_form #User_password').val();
  250. let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
  251. if (pswdVal.match(pattern)) {
  252. $('#pswd_info').hide()
  253. }
  254. else {
  255. $('#pswd_info').show()
  256. }
  257. //validate number
  258. if (pswd.match(/\d/)) {
  259. $('#chck_number').removeClass('pswd_invalid').addClass('pswd_valid');
  260. } else {
  261. $('#chck_number').removeClass('pswd_valid').addClass('pswd_invalid');
  262. }
  263. };
  264. //you have to use keyup, because keydown will not catch the currently entered value
  265. $('#register_form #User_password').keyup(function () {
  266. // set password variable
  267. var pswd = $(this).val();
  268. passwordValidate(pswd);
  269. }).focus(function () {
  270. let pswdVal = $('#register_form #User_password').val();
  271. let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
  272. if (pswdVal.match(pattern)) {
  273. $('#pswd_info').hide()
  274. }
  275. else {
  276. $('#pswd_info').show()
  277. }
  278. }).blur(function () {
  279. $('#pswd_info').hide();
  280. });
  281. // function to validate user entered email
  282. function validateEmail(userEmail) {
  283. var pattern =
  284. /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  285. return $.trim(userEmail).match(pattern) ? true : false;
  286. }
  287. // function to validate user entered password
  288. function validatepassword(userPassword) {
  289. var pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
  290. return $.trim(userPassword).match(pattern) ? true : false;
  291. }
  292. registerForm.find("#User_Email,#User_password").keypress(function (e) {
  293. if (e.which == 13)
  294. document.getElementById("register_btn").click();
  295. });
  296. // this will be triggered on clicking continue in signup form
  297. $("#register_btn").click(function () {
  298. registerForm.find(".loader-btn").show();
  299. $(this).hide();
  300. let userEmail = registerForm.find("#User_Email").val();
  301. let userPassword = registerForm.find("#User_password").val();
  302. let emailInput = registerForm.find(".email-login-inputgroup");
  303. let passwordInput = registerForm.find(".password-login-inputgroup");
  304. if (userEmail == "") {
  305. emailInput.find('#User_Email').addClass('is-invalid');
  306. emailInput.find('.form-floating').addClass('is-invalid');
  307. emailInput.find('.invalid-feedback').text('Please enter your email');
  308. registerForm.find(".loader-btn").hide();
  309. $(this).show();
  310. }
  311. if (userPassword == "") {
  312. passwordInput.find('#User_password').addClass('is-invalid');
  313. passwordInput.find('.form-floating').addClass('is-invalid');
  314. registerForm.find(".loader-btn").hide();
  315. $(this).show();
  316. }
  317. else {
  318. emailInput.find('#User_Email').removeClass('is-invalid');
  319. emailInput.find('.form-floating').removeClass('is-invalid');
  320. passwordInput.find('#User_password').removeClass('is-invalid');
  321. passwordInput.find('.form-floating').removeClass('is-invalid');
  322. if (validateEmail(userEmail)) {
  323. $('#register_form .email-password-group').hide();
  324. $('#register_form .otp-input-group').show();
  325. $('#register_form .otp-input-group .otp-sent-email').text(userEmail);
  326. userRegistration();
  327. } else {
  328. emailInput.find('#User_Email').addClass('is-invalid');
  329. emailInput.find('.form-floating').addClass('is-invalid');
  330. emailInput.find('.invalid-feedback').text('Please enter a valid email');
  331. registerForm.find(".loader-btn").hide();
  332. $(this).show();
  333. }
  334. }
  335. });
  336. $('#forgotPassword').click(function () {
  337. $('.login-email-password-div').hide();
  338. $('.login-forgot-passsword-div').show();
  339. })
  340. function toasterOpts() {
  341. toastr.options = {
  342. "closeButton": true,
  343. "debug": false,
  344. "newestOnTop": true,
  345. "progressBar": true,
  346. "positionClass": "toast-top-center",
  347. "preventDuplicates": true,
  348. "showDuration": "300",
  349. "hideDuration": "1000",
  350. "timeOut": "3000",
  351. "extendedTimeOut": "1000",
  352. "showEasing": "swing",
  353. "hideEasing": "linear",
  354. "showMethod": "fadeIn",
  355. "hideMethod": "fadeOut"
  356. }
  357. }
  358. }
  359. initLogin();