апи.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. function sendVerificationCode(email) {
  2. if (!email.includes('@gmail.com')) {
  3. document.getElementById('errorMessage').textContent = 'Пожалуйста, введите адрес электронной почты Gmail.';
  4. document.getElementById('errorPopup').style.display = 'block';
  5. return;
  6. }
  7. fetch('/send_code', {
  8. method: 'POST',
  9. headers: {
  10. 'Content-Type': 'application/json'
  11. },
  12. body: JSON.stringify({ email: email })
  13. })
  14. .then(response => {
  15. if (response.ok) {
  16. // Код успешно отправлен
  17. alert('Код отправлен на вашу почту!');
  18. } else {
  19. // Ошибка отправки кода
  20. document.getElementById('errorMessage').textContent = 'Ошибка отправки кода!';
  21. document.getElementById('errorPopup').style.display = 'block';
  22. }
  23. })
  24. .catch(error => {
  25. // Ошибка связи с сервером
  26. document.getElementById('errorMessage').textContent = 'Ошибка сервера!';
  27. document.getElementById('errorPopup').style.display = 'block';
  28. });
  29. }
  30. function registerUser(name, phone, email, code, password) {
  31. fetch('/register', {
  32. method: 'POST',
  33. headers: {
  34. 'Content-Type': 'application/json'
  35. },
  36. body: JSON.stringify({ name: name, phone: phone, email: email, code: code, password: password })
  37. })
  38. .then(response => {
  39. if (response.ok) {
  40. // Регистрация успешна
  41. document.getElementById('successPopup').style.display = 'block';
  42. } else {
  43. // Ошибка регистрации
  44. document.getElementById('errorMessage').textContent = 'Ошибка регистрации!';
  45. document.getElementById('errorPopup').style.display = 'block';
  46. }
  47. })
  48. .catch(error => {
  49. // Ошибка связи с сервером
  50. document.getElementById('errorMessage').textContent = 'Ошибка сервера!';
  51. document.getElementById('errorPopup').style.display = 'block';
  52. });
  53. }