test.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Login and Registration</title>
  7. <link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.2/css/bootstrap.min.css">
  8. <style>
  9. html, body {
  10. height: 100%;
  11. }
  12. body {
  13. display: flex;
  14. justify-content: center;
  15. align-items: center;
  16. }
  17. .container {
  18. width: 100%;
  19. max-width: 400px;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div class="container">
  25. <h1 class="text-center my-5">Login and Registration</h1>
  26. <form id="auth-form">
  27. <div class="mb-3">
  28. <label for="email" class="form-label">Email address</label>
  29. <input type="email" class="form-control" id="email">
  30. </div>
  31. <div class="mb-3">
  32. <label for="password" class="form-label">Password</label>
  33. <input type="password" class="form-control" id="password">
  34. </div>
  35. <div class="mb-3 form-check">
  36. <input type="checkbox" class="form-check-input" id="register-checkbox">
  37. <label class="form-check-label" for="register-checkbox">Register</label>
  38. </div>
  39. <button type="submit" class="btn btn-primary">Submit</button>
  40. </form>
  41. </div>
  42. <script src="//cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  43. <script>
  44. const form = document.getElementById('auth-form');
  45. const registerCheckbox = document.getElementById('register-checkbox');
  46. form.addEventListener('submit', async (e) => {
  47. e.preventDefault();
  48. const email = document.getElementById('email').value;
  49. const password = document.getElementById('password').value;
  50. const url = registerCheckbox.checked ? '/register' : '/login';
  51. try {
  52. const response = await axios.post(url, { email, password });
  53. console.log(response);
  54. } catch (error) {
  55. console.error(error);
  56. }
  57. });
  58. </script>
  59. </body>
  60. </html>