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.

64 lines
1.5 KiB

  1. if (localStorage.getItem("token")!==null) {
  2. // redirect to dashboard
  3. window.location.href = "/dashboard.html";
  4. }
  5. function register() {
  6. let email = document.getElementById("registerEmail").value;
  7. let name = document.getElementById("registerName").value;
  8. let password = document.getElementById("registerPassword").value;
  9. let data = {
  10. email: email,
  11. name: name,
  12. password: password
  13. };
  14. axios.post(url + "/register", data)
  15. .then(function (res) {
  16. console.log(res.data);
  17. document.getElementById("register").innerHTML = `
  18. <br><br>
  19. <div class="alert alert-success" role="alert">
  20. Registration complete. You can now Login
  21. </div>
  22. <br><br>
  23. `;
  24. })
  25. .catch(function (error) {
  26. console.log(error);
  27. document.getElementById("registerErr").innerHTML = `
  28. <br><br>
  29. <div class="alert alert-danger" role="alert">
  30. Something went wrong on register
  31. </div>
  32. <br><br>
  33. `;
  34. });
  35. }
  36. function login() {
  37. let email = document.getElementById("loginEmail").value;
  38. let password = document.getElementById("loginPassword").value;
  39. let data = {
  40. email: email,
  41. password: password
  42. };
  43. axios.post(url + "/login", data)
  44. .then(function (res) {
  45. console.log(res.data);
  46. localStorage.setItem("token", res.data.token);
  47. window.location.href = "/dashboard.html";
  48. })
  49. .catch(function (error) {
  50. console.log(error);
  51. document.getElementById("loginErr").innerHTML = `
  52. <br><br>
  53. <div class="alert alert-danger" role="alert">
  54. Something went wrong on login
  55. </div>
  56. <br><br>
  57. `;
  58. });
  59. }