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.

42 lines
1022 B

  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. })
  18. .catch(function (error) {
  19. console.log(error);
  20. });
  21. }
  22. function login() {
  23. let email = document.getElementById("loginEmail").value;
  24. let password = document.getElementById("loginPassword").value;
  25. let data = {
  26. email: email,
  27. password: password
  28. };
  29. axios.post(url + "/login", data)
  30. .then(function (res) {
  31. console.log(res.data);
  32. localStorage.setItem("token", res.data.token);
  33. window.location.href = "/dashboard.html";
  34. })
  35. .catch(function (error) {
  36. console.log(error);
  37. });
  38. }