Ei kuvausta
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_ing.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. function initLogin() {
  2. // alert('as')
  3. // Command: toastr["success"]("Logged in successfully")
  4. // Command: toastr["success"]("My name is Inigo Montoya. You killed my father. Prepare to die!")
  5. // toasterOpts();
  6. let reg_name, reg_email, reg_number, reg_pwd, reg_otp_email;
  7. let loginForm = $("#login_form");
  8. let registerForm = $("#register_form");
  9. $("#register_form .otp-input-group input.press").on("paste", function (p) {
  10. var data = p.originalEvent.clipboardData.getData("text");
  11. var dataLength = data.length;
  12. for (var i = 0; i < dataLength; i++) {
  13. var input = $(
  14. '#register_form .otp-input-group input[tabindex="' + (i + 1) + '"]'
  15. );
  16. input.val(data.charAt(i));
  17. if (input.val().length >= input.attr("maxlength")) {
  18. var nextInput = $(
  19. '#register_form .otp-input-group input[tabindex="' + (i + 2) + '"]'
  20. );
  21. if (nextInput) {
  22. nextInput.focus();
  23. }
  24. }
  25. }
  26. p.preventDefault();
  27. });
  28. $('#register_form .otp-input-group input[type="text"]').on(
  29. "keyup",
  30. function (e) {
  31. if ($(this).val().length >= $(this).attr("maxlength")) {
  32. if (e.keyCode !== 9 && e.keyCode !== 16) {
  33. var tabIndex = parseInt($(this).attr("tabindex")) + 1;
  34. $(
  35. '#register_form .otp-input-group input[tabindex="' +
  36. $(this).attr("tabindex") +
  37. '"]'
  38. ).val($(this).val());
  39. $(
  40. '#register_form .otp-input-group input[tabindex="' + tabIndex + '"]'
  41. ).focus();
  42. }
  43. } else {
  44. if (e.keyCode === 8) {
  45. var tabIndex = parseInt($(this).attr("tabindex")) - 1;
  46. $(
  47. '#register_form .otp-input-group input[tabindex="' + tabIndex + '"]'
  48. ).focus();
  49. }
  50. }
  51. }
  52. );
  53. loginForm.find("#User_Email,#User_password").keypress(function (e) {
  54. if (e.which == 13) $("#Login_btn").click();
  55. });
  56. $("#Login_btn").click(function () {
  57. $('.error_msg').hide();
  58. // loginForm.find(".loader-btn").show();
  59. let userEmail = loginForm.find("#User_Email").val();
  60. let userPassword = loginForm.find("#User_password").val();
  61. let emailInput = loginForm.find(".email-login-inputgroup");
  62. let passwordInput = loginForm.find(".password-login-inputgroup");
  63. if (userEmail == "") {
  64. emailInput.find("#User_Email").addClass("is-invalid");
  65. emailInput.find(".form-floating").addClass("is-invalid");
  66. emailInput.find(".invalid-feedback").text("Please enter your email");
  67. loginForm.find(".loader-btn").hide();
  68. $(this).show();
  69. }
  70. if (userPassword == "") {
  71. passwordInput.find("#User_password").addClass("is-invalid");
  72. passwordInput.find(".form-floating").addClass("is-invalid");
  73. loginForm.find(".loader-btn").hide();
  74. $(this).show();
  75. } else {
  76. emailInput.find("#User_Email").removeClass("is-invalid");
  77. emailInput.find(".form-floating").removeClass("is-invalid");
  78. passwordInput.find("#User_password").removeClass("is-invalid");
  79. passwordInput.find(".form-floating").removeClass("is-invalid");
  80. if (validateEmail(userEmail)) {
  81. let port = SERVERNAME
  82. // let port = "http://localhost:3088";
  83. let url = `${port}/account/getuserbyphoneormail/${userEmail}/${userEmail}`;
  84. getDataStatAxios(url, userEmail);
  85. } else {
  86. loginForm.find(".loader-btn").hide();
  87. $(this).show();
  88. emailInput.find("#User_Email").addClass("is-invalid");
  89. emailInput.find(".form-floating").addClass("is-invalid");
  90. emailInput.find(".invalid-feedback").text("Please enter a valid email");
  91. }
  92. }
  93. });
  94. async function getDataStatAxios(url, userEmail) {
  95. const config = {
  96. url,
  97. method: "get",
  98. };
  99. let response = await axios(config);
  100. if (response.data.result == null) {
  101. $('.error_msg').show();
  102. $('.error_msg .error_msg_res').html(`User doesn't exists with the email, <a href="#" class="alert-link register_sectionbtn" id="register_sectionbtn">Sign Up </a>`);
  103. $(".register_sectionbtn").click(function(){
  104. $(".login_section").css("display","none");
  105. $(".register_section").css("display","block");
  106. $(".login_section").find("#User_Email").removeClass("is-invalid");
  107. $(".login_section").find(".form-floating").removeClass("is-invalid");
  108. $(".login_section").find("#User_password").removeClass("is-invalid");
  109. $(".login_section").find(".form-floating").removeClass("is-invalid");
  110. $('.error_msg').hide();
  111. });
  112. // toasterOpts();
  113. // Command: toastr["error"]("Please enter Valid email / password");
  114. } else {
  115. let userEmail = $("#User_Email").val();
  116. let userPassword = $("#User_password").val();
  117. const loginPayload = {
  118. username: userEmail,
  119. Password: userPassword,
  120. UnibaseId: "",
  121. RememberMe: false,
  122. };
  123. $("#Login_btn").hide();
  124. $(".loader-btn").show();
  125. const res = await postAPIService(
  126. `bizgaze/crm/webapi/crmuserlogin`,
  127. loginPayload
  128. );
  129. debugger;
  130. console.log(res);
  131. $(".loader-btn").hide();
  132. $("#Login_btn").show();
  133. if (res.data.message == "200") {
  134. debugger;
  135. // Command: toastr["success"]("Logged in successfully")
  136. // toasterOpts();
  137. COOKIE_HELPER_ACTIONS.setCookie({
  138. token: res.data.result.sessionId,
  139. userid: res.data.result.userId,
  140. ...res.data.result
  141. });
  142. // setInitLoginLocal();
  143. window.localStorage.setItem("Useremail", userEmail);
  144. //window.localStorage.setItem("Userpassword", userPassword);
  145. window.localStorage.setItem("Isloggedintoaster", true);
  146. window.localStorage.setItem("Isloggedin", true);
  147. const isCartAdded = localStorage.getItem(CART_ADD);
  148. if(isCartAdded){
  149. localStorage.removeItem(CART_ADD);
  150. window.location.href = `/selectdelivery.html`;
  151. return;
  152. }
  153. window.location.href = `./index.html`;
  154. } else {
  155. $('.error_msg').show();
  156. $('.error_msg .error_msg_res').html(res.data.message + ' <a class="validate_mail text-danger"><b>Validate Email</b></a>');
  157. // toasterOpts();
  158. // Command: toastr["error"]()
  159. /*Email validation*/
  160. $('.validate_mail').click(function(){
  161. $(".login_section").hide();
  162. $(".email-validate-div").show();
  163. $('.error_msg').hide();
  164. })
  165. }
  166. }
  167. }
  168. // this function will be triggered on new user registration
  169. async function userRegistration() {
  170. reg_form = $("#register_form");
  171. // reg_name = $("#User_Name").val();
  172. reg_email = reg_form.find("#User_Email").val();
  173. // reg_otp_email = $("#User_otp_Email").val();
  174. // reg_number = $("#user_number").val();
  175. reg_pwd = reg_form.find("#User_password").val();
  176. let userName = reg_email.split("@");
  177. let otpRes = null;
  178. const userRegistratioNPayload = {
  179. organizationtypeid: "2",
  180. organizationid: "0",
  181. contactid: "0",
  182. userid: "0",
  183. username: "0",
  184. users_phonenumber: "0",
  185. password: reg_pwd,
  186. users_emailaddress: "0",
  187. emailaddress: reg_email,
  188. contactname: userName[0],
  189. phonenumber: "0",
  190. branchid: "0",
  191. tenantname: "Anwi Systems",
  192. rolename: "Customer Admin",
  193. currencyid: "0",
  194. customerformuniqueid: "Bizgaze_Platform_Crm_RegisterCRMUser",
  195. };
  196. debugger;
  197. $('#register_btn').hide()
  198. $(".loader-btn").show();
  199. debugger;
  200. const res = await postAPIService(
  201. `bizgaze/crm/webapi/registercrmuser`,
  202. userRegistratioNPayload
  203. );
  204. console.log(res, "register");
  205. $(".loader-btn").hide();
  206. $('#register_btn').show()
  207. if (res.data.code == "404" ) {
  208. // toasterOpts();
  209. // Command: toastr["error"](res.data.message)
  210. $('.error_msg').show();
  211. $('.error_msg .error_msg_res').html(res.data.message);
  212. return;
  213. }
  214. else {
  215. $("#register_form .email-password-group").hide();
  216. $("#register_form .register_otp.otp-input-group").show();
  217. }
  218. $("#proceed").click(async function () {
  219. let userEnterOtp = "";
  220. let userEmail = registerForm.find("#User_Email").val();
  221. $(".otp-input-group input").each(function () {
  222. let presVal = $(this).val();
  223. userEnterOtp += presVal;
  224. });
  225. console.log(userEnterOtp);
  226. debugger;
  227. const userotppayload = {
  228. email: userEmail,
  229. otpid: res.data.result.OtpId,
  230. userotp: userEnterOtp,
  231. };
  232. $(".loader-btn").show();
  233. $('#proceed').hide()
  234. otpRes = await postAPIService(
  235. `bizgaze/crm/webapi/ValidateOtp`,
  236. userotppayload
  237. );
  238. $(".loader-btn").hide();
  239. $('#proceed').show()
  240. debugger;
  241. console.log(otpRes, "otp");
  242. const verifyotpStatus = otpRes.data.result;
  243. if (verifyotpStatus == "Otp verified successfully") {
  244. const loginPayload = {
  245. username: reg_email,
  246. Password: reg_pwd,
  247. UnibaseId: "",
  248. RememberMe: false,
  249. };
  250. const res = await postAPIService(
  251. `bizgaze/crm/webapi/crmuserlogin`,
  252. loginPayload
  253. );
  254. if (res.data.message == "200") {
  255. debugger;
  256. // Command: toastr["success"]("Logged in successfully")
  257. // toasterOpts();
  258. COOKIE_HELPER_ACTIONS.setCookie({
  259. token: res.data.result.sessionId,
  260. userid: res.data.result.userId,
  261. ...res.data.result
  262. });
  263. // setInitLoginLocal();
  264. window.localStorage.setItem("Useremail", userEmail);
  265. //window.localStorage.setItem("Userpassword", userPassword);
  266. window.localStorage.setItem("isaccountCreated", true);
  267. const isCartAdded = localStorage.getItem(CART_ADD);
  268. if(isCartAdded){
  269. localStorage.removeItem(CART_ADD);
  270. window.location.href = `/selectdelivery.html`;
  271. return;
  272. }
  273. window.location.href = `./index.html`;
  274. } else {
  275. // toasterOpts();
  276. // Command: toastr["error"](res.data.message)
  277. $('.error_msg').show();
  278. $('.error_msg .error_msg_res').html(res.data.message);
  279. }
  280. } else {
  281. // toasterOpts();
  282. // Command: toastr["error"]("Please enter Valid OTP");
  283. $('.error_msg').show();
  284. $('.error_msg .error_msg_res').html("Please enter Valid OTP");
  285. }
  286. });
  287. }
  288. // to validate password on keyup in password input field
  289. function passwordValidate(pswd) {
  290. if (pswd.length < 8) {
  291. $("#chck_length").removeClass("pswd_valid").addClass("pswd_invalid");
  292. } else {
  293. $("#chck_length").removeClass("pswd_invalid").addClass("pswd_valid");
  294. }
  295. // validate uppercase letter
  296. if (pswd.match(/[A-Z]/)) {
  297. $("#chck_capital").removeClass("pswd_invalid").addClass("pswd_valid");
  298. } else {
  299. $("#chck_capital").removeClass("pswd_valid").addClass("pswd_invalid");
  300. }
  301. //validate special letter
  302. if (pswd.match(/[!@#$%^&*]/)) {
  303. $("#chck_special").removeClass("pswd_invalid").addClass("pswd_valid");
  304. } else {
  305. $("#chck_special").removeClass("pswd_valid").addClass("pswd_invalid");
  306. }
  307. let pswdVal = $("#register_form #User_password").val();
  308. let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/;
  309. if (pswdVal.match(pattern)) {
  310. $(".pswd_info").hide();
  311. } else {
  312. $(".pswd_info").show();
  313. }
  314. //validate number
  315. if (pswd.match(/\d/)) {
  316. $("#chck_number").removeClass("pswd_invalid").addClass("pswd_valid");
  317. } else {
  318. $("#chck_number").removeClass("pswd_valid").addClass("pswd_invalid");
  319. }
  320. }
  321. //you have to use keyup, because keydown will not catch the currently entered value
  322. $("#register_form #User_password")
  323. .keyup(function () {
  324. // set password variable
  325. var pswd = $(this).val();
  326. passwordValidate(pswd);
  327. })
  328. .focus(function () {
  329. let pswdVal = $("#register_form #User_password").val();
  330. let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{11,}$/;
  331. if (pswdVal.match(pattern)) {
  332. $(".pswd_info").hide();
  333. } else {
  334. $(".pswd_info").show();
  335. }
  336. })
  337. .blur(function () {
  338. $(".pswd_info").hide();
  339. });
  340. // function to validate user entered email
  341. function validateEmail(userEmail) {
  342. 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})(\]?)$/;
  343. // return $.trim(userEmail).test(pattern) ? true : false;
  344. return pattern.test(userEmail) ? true : false;
  345. }
  346. // function to validate user entered password
  347. function validatepassword(userPassword) {
  348. var pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
  349. // return $.trim(userPassword).test(pattern) ? true : false;
  350. return pattern.test(userPassword) ? true : false;
  351. }
  352. registerForm.find("#User_Email,#User_password").keypress(function (e) {
  353. if (e.which == 13) $("#register_btn").click();
  354. });
  355. // this will be triggered on clicking continue in signup form
  356. $("#register_btn").click(function () {
  357. $('.error_msg').hide();
  358. registerForm.find(".loader-btn").show();
  359. $(this).hide();
  360. let userEmail = registerForm.find("#User_Email").val();
  361. let userPassword = registerForm.find("#User_password").val();
  362. let emailInput = registerForm.find(".email-login-inputgroup");
  363. let passwordInput = registerForm.find(".password-login-inputgroup");
  364. if (userEmail == "") {
  365. emailInput.find("#User_Email").addClass("is-invalid");
  366. emailInput.find(".form-floating").addClass("is-invalid");
  367. emailInput.find(".invalid-feedback").text("Please enter your email");
  368. registerForm.find(".loader-btn").hide();
  369. $(this).show();
  370. }
  371. if (userPassword == "") {
  372. passwordInput.find("#User_password").addClass("is-invalid");
  373. passwordInput.find(".form-floating").addClass("is-invalid");
  374. registerForm.find(".loader-btn").hide();
  375. $(this).show();
  376. } else {
  377. emailInput.find("#User_Email").removeClass("is-invalid");
  378. emailInput.find(".form-floating").removeClass("is-invalid");
  379. passwordInput.find("#User_password").removeClass("is-invalid");
  380. passwordInput.find(".form-floating").removeClass("is-invalid");
  381. let Email_valid = validateEmail(userEmail);
  382. let Pwd_valid = validatepassword(userPassword);
  383. if (Email_valid === true && Pwd_valid === true) {
  384. userRegistration();
  385. $("#register_form .otp-input-group .otp-sent-email").text(userEmail);
  386. } else if(Email_valid === false) {
  387. emailInput.find("#User_Email").addClass("is-invalid");
  388. emailInput.find(".form-floating").addClass("is-invalid");
  389. emailInput.find(".invalid-feedback").text("Please enter a valid email");
  390. registerForm.find(".loader-btn").hide();
  391. $(this).show();
  392. }else if(Pwd_valid === false){
  393. passwordInput.find("#User_password").addClass("is-invalid");
  394. passwordInput.find(".form-floating").addClass("is-invalid");
  395. passwordInput.find(".invalid-feedback").text("Please check the password!");
  396. registerForm.find(".loader-btn").hide();
  397. $(this).show();
  398. }
  399. }
  400. });
  401. $(".pswd_eye").click(function(){
  402. let eyeClass = $(this).find('svg').hasClass("fa-eye-slash");
  403. if(eyeClass == true){
  404. $(this).find('svg').removeClass("fa-eye-slash");
  405. $(this).find('svg').addClass("fa-eye");
  406. $(this).siblings('input').attr('type','password')
  407. }else{
  408. $(this).find('svg').removeClass("fa-eye");
  409. $(this).find('svg').addClass("fa-eye-slash");
  410. $(this).siblings('input').attr('type','text')
  411. }
  412. })
  413. $("#forgotPassword").click(function () {
  414. $(".login-email-password-div").hide();
  415. $(".login-forgot-password-div").show();
  416. });
  417. $("#forgot_Password_Back").click(function () {
  418. $(".login-forgot-password-div").hide();
  419. $(".login-email-password-div").show();
  420. });
  421. $("#forgot_password_submit").click(async function () {
  422. let forgot_email = $("#forgot_User_Email").val();
  423. if(forgot_email == ''){
  424. $('#forgot_User_Email').addClass('is-invalid')
  425. $('#forgot_User_Email').after(`<div class="invalid-feedback">Please enter Valid email</div>`);
  426. return
  427. }
  428. else{
  429. debugger;
  430. let port = SERVERNAME
  431. // let port = "http://localhost:3088";
  432. let url = `${port}/account/getuserbyphoneormail/${forgot_email}/${forgot_email}`;
  433. const config = {
  434. url,
  435. method: "get",
  436. };
  437. $(".loader-btn").show();
  438. $('#forgot_password_submit').hide()
  439. let response = await axios(config);
  440. debugger;
  441. console.log(response);
  442. $(".loader-btn").hide();
  443. $('#forgot_password_submit').show()
  444. if (response.data.result != null) {
  445. debugger;
  446. console.log(response.data);
  447. const forgotpassPayload = {
  448. firstname: "",
  449. lastname: "",
  450. contactnumber: "",
  451. email: "",
  452. tenantname: "",
  453. contactoremail: response.data.result.email,
  454. IsSignup: false,
  455. IsRegisterUser: false,
  456. IsForgotPswd: true,
  457. UnibaseId: response.data.result.userName,
  458. OtpId: 0,
  459. UserOtp: "",
  460. };
  461. $('#forgot_password_submit').hide()
  462. $(".loader-btn").show();
  463. const forgetpassRes = await postAPIService(
  464. `account/sendotp`,
  465. forgotpassPayload
  466. );
  467. $(".loader-btn").hide();
  468. console.log(forgetpassRes);
  469. $(".email-validation").hide();
  470. $('.user_email').html(forgot_email)
  471. $(".otp-validation .otp-input-group").show();
  472. $(".otp-validation .otp-input-group").on("paste", function (p) {
  473. let data = p.originalEvent.clipboardData.getData("text");
  474. let dataLength = data.length;
  475. for (let i = 0; i < dataLength; i++) {
  476. let input = $(
  477. '.otp-validation .otp-input-group input[tabindex="' + (i + 1) + '"]'
  478. );
  479. input.val(data.charAt(i));
  480. if (input.val().length >= input.attr("maxlength")) {
  481. let nextInput = $(
  482. '.otp-validation .otp-input-group input[tabindex="' +
  483. (i + 2) +
  484. '"]'
  485. );
  486. if (nextInput) {
  487. nextInput.focus();
  488. }
  489. }
  490. }
  491. p.preventDefault();
  492. });
  493. $('.otp-validation .otp-input-group input[type="text"]').on(
  494. "keyup",
  495. function (e) {
  496. if ($(this).val().length >= $(this).attr("maxlength")) {
  497. if (e.keyCode !== 9 && e.keyCode !== 16) {
  498. let tabIndex = parseInt($(this).attr("tabindex")) + 1;
  499. $(
  500. '.otp-validation .otp-input-group input[tabindex="' +
  501. $(this).attr("tabindex") +
  502. '"]'
  503. ).val($(this).val());
  504. $(
  505. '.otp-validation .otp-input-group input[tabindex="' +
  506. tabIndex +
  507. '"]'
  508. ).focus();
  509. }
  510. } else {
  511. if (e.keyCode === 8) {
  512. let tabIndex = parseInt($(this).attr("tabindex")) - 1;
  513. $(
  514. '.otp-validation .otp-input-group input[tabindex="' +
  515. tabIndex +
  516. '"]'
  517. ).focus();
  518. }
  519. }
  520. }
  521. );
  522. $("#Forgot_pass_proceed").click(async function () {
  523. debugger;
  524. let userotp='';
  525. $(".otp-validation .otp-input-group input").each(function () {
  526. let presVal = $(this).val();
  527. userotp += presVal;
  528. });
  529. console.log(userotp);
  530. const validateForgotpass = {
  531. email: forgot_email,
  532. otpid: forgetpassRes.data,
  533. userotp: userotp,
  534. };
  535. $('#Forgot_pass_proceed').hide()
  536. $(".loader-btn").show();
  537. const forgetpassResotp = await postAPIService(
  538. `hyperfusion/validateotp`,
  539. validateForgotpass
  540. );
  541. $(".loader-btn").hide();
  542. $('#Forgot_pass_proceed').show()
  543. console.log(forgetpassResotp);
  544. const Resotp = forgetpassResotp.data.result;
  545. if (Resotp == "Otp verified successfully") {
  546. $(".login-forgot-password-details-div").show();
  547. $(".otp-validation .otp-input-group").hide();
  548. } else {
  549. // toasterOpts()
  550. // Command: toastr["error"]("Please enter Valid OTP");
  551. $('.error_msg').show();
  552. $('.error_msg .error_msg_res').html("Please enter Valid OTP");
  553. }
  554. });
  555. $("#forgot_password_details_submit").click(async function () {
  556. debugger;
  557. let pswdone =$("#forgot-password-input-one").val();
  558. let pswdtwo =$("#forgot-password-input-two").val();
  559. if(pswdone == pswdtwo) {
  560. const forgotpassPayload = {
  561. username: response.data.result.userName,
  562. password: pswdtwo,
  563. };
  564. $("#forgot_password_details_submit").hide();
  565. $(".loader-btn").show();
  566. const forgetpassRes = await postAPIService(
  567. `account/UpdatePassword`,
  568. forgotpassPayload
  569. );
  570. console.log(forgetpassRes);
  571. $(".loader-btn").hide();
  572. $("#forgot_password_details_submit").show();
  573. window.localStorage.setItem('Ispasswordupdate',true)
  574. window.location.href = `./myaccount.html`;
  575. }else {
  576. $("#forgot-password-input-one").addClass('is-invalid');
  577. $("#forgot-password-input-two").addClass('is-invalid')
  578. $('.password_display').text('Passwords are not matched !').addClass('text-danger')
  579. }
  580. });
  581. }
  582. else{
  583. $('#forgot_User_Email').addClass('is-invalid');
  584. $('#forgot_User_Email').after(`<div class="invalid-feedback">Please enter Valid email</div>`);
  585. }
  586. }
  587. });
  588. $(".user_pass")
  589. .keyup(function () {
  590. // set password variable
  591. var pswd = $(this).val();
  592. passwordValidate(pswd);
  593. $('.pswd_info').hide();
  594. $(this).parent().siblings('.pswd_info').show();
  595. })
  596. .focus(function () {
  597. let pswdVal = $(this).val();
  598. let pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/;
  599. if (pswdVal.match(pattern)) {
  600. $(this).parent().siblings('.pswd_info').hide();
  601. } else {
  602. $(this).parent().siblings('.pswd_info').show();
  603. }
  604. })
  605. .blur(function () {
  606. $(this).parent().siblings('.pswd_info').hide();
  607. });
  608. function toasterOpts(){
  609. toastr.options = {
  610. "closeButton": true,
  611. "debug": false,
  612. "newestOnTop": true,
  613. "progressBar": true,
  614. "positionClass": "toast-top-center",
  615. "preventDuplicates": true,
  616. "onclick": null,
  617. "showDuration": "300",
  618. "hideDuration": "1000",
  619. "timeOut": "5000",
  620. "extendedTimeOut": "1000",
  621. "showEasing": "swing",
  622. "hideEasing": "linear",
  623. "showMethod": "fadeIn",
  624. "hideMethod": "fadeOut"
  625. }
  626. }
  627. }
  628. $("#email_validate_submit").click(async function () {
  629. let vaidate_otp;
  630. let validate_email = $("#email_validation_input").val();
  631. if(validate_email == ''){
  632. $('#email_validation_input').addClass('is-invalid')
  633. $('#email_validation_input').after(`<div class="invalid-feedback">Please enter Valid email</div>`);
  634. return
  635. }
  636. else{
  637. debugger;
  638. let port = SERVERNAME;
  639. // let port = "http://localhost:3088";
  640. let url = `${port}/account/getuserbyphoneormail/${validate_email}/${validate_email}`;
  641. const config = {
  642. url,
  643. method: "get",
  644. };
  645. $(".loader-btn").show();
  646. $('#email_validate_submit').hide()
  647. let response = await axios(config);
  648. debugger;
  649. console.log(response);
  650. $(".loader-btn").hide();
  651. $('#email_validate_submit').show()
  652. if (response.data.result != null) {
  653. debugger;
  654. console.log(response.data);
  655. const forgotpassPayload = {
  656. firstname: "",
  657. lastname: "",
  658. contactnumber: "",
  659. email: "",
  660. tenantname: "",
  661. contactoremail: response.data.result.email,
  662. IsSignup: false,
  663. IsRegisterUser: false,
  664. IsForgotPswd: true,
  665. UnibaseId: response.data.result.userName,
  666. OtpId: 0,
  667. UserOtp: "",
  668. };
  669. $('#email_validate_submit').hide()
  670. $(".loader-btn").show();
  671. const validate_email_res = await postAPIService(
  672. `account/sendotp`,
  673. forgotpassPayload
  674. );
  675. $(".loader-btn").hide();
  676. vaidate_otp = validate_email_res.data;
  677. console.log(validate_email_res);
  678. $(".email-validation").hide();
  679. $('.user_email').html(validate_email)
  680. $(".otp-validation .otp-input-group").show();
  681. $(".otp-validation .otp-input-group").on("paste", function (p) {
  682. let data = p.originalEvent.clipboardData.getData("text");
  683. let dataLength = data.length;
  684. for (let i = 0; i < dataLength; i++) {
  685. let input = $(
  686. '.otp-validation .otp-input-group input[tabindex="' + (i + 1) + '"]'
  687. );
  688. input.val(data.charAt(i));
  689. if (input.val().length >= input.attr("maxlength")) {
  690. let nextInput = $(
  691. '.otp-validation .otp-input-group input[tabindex="' +
  692. (i + 2) +
  693. '"]'
  694. );
  695. if (nextInput) {
  696. nextInput.focus();
  697. }
  698. }
  699. }
  700. p.preventDefault();
  701. });
  702. }
  703. else{
  704. $('#email_validation_input').addClass('is-invalid');
  705. $('#email_validation_input').after(`<div class="invalid-feedback">Please enter Valid email</div>`);
  706. }
  707. }
  708. $("#email_validate_proceed").click(async function () {
  709. debugger;
  710. let userotp='';
  711. let validate_email = $("#email_validation_input").val();
  712. $(".email-validate-div .otp-validation .otp-input-group input").each(function () {
  713. let presVal = $(this).val();
  714. userotp += presVal;
  715. });
  716. if(userotp.length == 6){
  717. const validateForgotpass = {
  718. email: validate_email,
  719. otpid: vaidate_otp,
  720. userotp: userotp,
  721. };
  722. $('#email_validate_proceed').hide()
  723. $(".loader-btn").show();
  724. const validate_email_resopt = await postAPIService(
  725. `hyperfusion/validateotp`,
  726. validateForgotpass
  727. );
  728. $(".loader-btn").hide();
  729. $('#email_validate_proceed').show()
  730. const Resotp = validate_email_resopt.data.result;
  731. if (Resotp == "Otp verified successfully") {
  732. $(".login_section").show();
  733. $(".otp-validation .otp-input-group").hide();
  734. $("#email_validate_back").hide();
  735. $('.error_msg').hide();
  736. } else {
  737. // toasterOpts()
  738. // Command: toastr["error"]("Please enter Valid OTP");
  739. $('.error_msg').show();
  740. $('.error_msg .error_msg_res').html("Please enter Valid OTP");
  741. }
  742. }
  743. else{
  744. $('.error_msg').show();
  745. $('.error_msg .error_msg_res').html("Please enter OTP");
  746. }
  747. });
  748. });
  749. initLogin();