New UI layout
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

login.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. const serverUrl = 'https://test.bizgaze.app/';
  2. const emailInputEl = document.getElementById('email');
  3. const passwordInputEl = document.getElementById('password');
  4. const emailErrEl = document.getElementById('emailErrMsg');
  5. const passwordErrEl = document.getElementById('passwordErrMsg');
  6. const emailContainerEl = document.getElementById('emailBox');
  7. const passwordContainerEl = document.getElementById('passwordBox');
  8. const showPasswordChk = document.getElementById('showPassword');
  9. const emailNextBtn = document.getElementById('emailNextBtn');
  10. const renterEmailLink = document.getElementById('renterEmail');
  11. const loginSubmitBtn = document.getElementById('loginSubmitBtn');
  12. passwordContainerEl.style.display = 'none';
  13. emailInputEl.focus();
  14. function showPasswordBox() {
  15. const email = emailInputEl.value;
  16. if (validateEmailOrPhone()) {
  17. emailContainerEl.style.display = 'none';
  18. passwordContainerEl.style.display = 'block';
  19. document.getElementById('entered-email').innerHTML = email;
  20. passwordInputEl.focus();
  21. emailInputEl.classList.remove('error');
  22. emailErrEl.innerText = '';
  23. } else {
  24. emailInputEl.classList.add('error');
  25. emailErrEl.innerText = 'Please enter valid email or phone';
  26. }
  27. }
  28. function validateEmailOrPhone() {
  29. const value = emailInputEl.value.trim();
  30. const regx = /^[6-9]\d{9}$/;
  31. if (value.includes('@') || regx.test(value)) {
  32. return true;
  33. }
  34. return false;
  35. }
  36. function togglePassword() {
  37. const ele = document.getElementById('showPassword');
  38. const password = passwordInputEl;
  39. if (password.value.length > 0) {
  40. passwordInputEl.value = password.value;
  41. password.focus();
  42. if (ele.checked) {
  43. password.setAttribute('type', 'text');
  44. } else {
  45. password.setAttribute('type', 'password');
  46. }
  47. }
  48. }
  49. function onPasswordFocusOut() {
  50. const passwordLabel = document.getElementById('passwordLabel');
  51. if (passwordInputEl.value.length > 0) {
  52. passwordLabel.classList.add('password-fixed');
  53. } else {
  54. passwordLabel.classList.remove('password-fixed');
  55. }
  56. }
  57. function onEmailFocusOut() {
  58. const emailLabel = document.getElementById('emailLabel');
  59. if (emailInputEl.value.trim()) {
  60. emailLabel.classList.add('password-fixed');
  61. } else {
  62. emailLabel.classList.remove('password-fixed');
  63. }
  64. }
  65. function loginUser(email, password) {
  66. const postData = JSON.stringify({
  67. UserName: email,
  68. Password: password,
  69. UnibaseId: '',
  70. RememberMe: false,
  71. });
  72. const requestOptions = {
  73. method: 'POST',
  74. headers: {
  75. 'Content-Type': 'application/json',
  76. },
  77. body: postData,
  78. redirect: 'follow',
  79. };
  80. fetch(serverUrl + 'account/login', requestOptions)
  81. .then((response) => response.text())
  82. .then((result) => {
  83. const data = JSON.parse(result);
  84. if (data.status === 0) {
  85. setCookie('_idty', JSON.stringify(data.result), 1);
  86. window.location = '../authentication';
  87. } else {
  88. passwordErrEl.innerText = data.message;
  89. }
  90. })
  91. .catch((error) => {
  92. passwordErrEl.innerText = error;
  93. });
  94. }
  95. function validateLogin() {
  96. const email = emailInputEl.value;
  97. const password = passwordInputEl.value;
  98. if (password.trim().length !== 0) {
  99. loginUser(email, password);
  100. } else {
  101. passwordInputEl.classList.add('error');
  102. passwordErrEl.innerText = 'Please enter valid password';
  103. }
  104. }
  105. function reEnterEmailClickHandler() {
  106. emailContainerEl.style.display = 'block';
  107. passwordContainerEl.style.display = 'none';
  108. emailInputEl.focus();
  109. }
  110. function initializeEventListeners() {
  111. emailNextBtn.addEventListener('click', showPasswordBox);
  112. showPasswordChk.addEventListener('click', togglePassword);
  113. passwordInputEl.addEventListener('focusout', onPasswordFocusOut);
  114. emailInputEl.addEventListener('focusout', onEmailFocusOut);
  115. loginSubmitBtn.addEventListener('click', validateLogin);
  116. renterEmailLink.addEventListener('click', reEnterEmailClickHandler);
  117. }
  118. initializeEventListeners();