From f02c4054984fb8c12bfa4af9560a5b2be38810c0 Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Thu, 30 Jul 2020 20:16:54 +0200 Subject: Added views and server setup --- src/public/js/login.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/public/js/login.js (limited to 'src/public/js/login.js') diff --git a/src/public/js/login.js b/src/public/js/login.js new file mode 100644 index 0000000..681b02f --- /dev/null +++ b/src/public/js/login.js @@ -0,0 +1,18 @@ +const form = document.getElementById("login-form"); + +form.addEventListener('submit', async e => { + e.preventDefault(); + const username = document.getElementById("username").value; + const password = document.getElementById("password").value; + + const body = JSON.stringify({username, password}); + + const resp = await fetch("/user/login", { + method: "POST", + headers: {'Content-Type': 'application/json'}, + body, + }); + const res = await resp.json(); + if (res.success) location.replace("/"); + else alert("ASJHDOAISJDLKAJSD"); +}) \ No newline at end of file -- cgit v1.2.3