index.js 911 B

12345678910111213141516171819202122232425262728293031323334
  1. export default {
  2. form: null,
  3. display(){
  4. if(this.form === null){
  5. this.form = document.querySelector("#loginPage form");
  6. this.form.addEventListener("submit", (event)=>{
  7. this.submit(event);
  8. });
  9. }
  10. document.getElementById("loginPageEmail").focus();
  11. },
  12. async submit(event){
  13. event.preventDefault();
  14. const body = {
  15. email: document.getElementById("loginPageEmail").value,
  16. password: document.getElementById("loginPagePassword").value
  17. };
  18. const response = await fetch("/login", {
  19. method: "POST",
  20. headers: {"Content-Type": "application/json"},
  21. body: JSON.stringify(body)
  22. });
  23. const data = await response.json();
  24. if(!response.ok) return notify("error", data.msg);
  25. openPage("dashboard");
  26. }
  27. }