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 ++++++++++++++++++ src/public/js/setup.js | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/public/js/login.js create mode 100644 src/public/js/setup.js (limited to 'src/public') 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 diff --git a/src/public/js/setup.js b/src/public/js/setup.js new file mode 100644 index 0000000..ef31e18 --- /dev/null +++ b/src/public/js/setup.js @@ -0,0 +1,21 @@ +const form = document.getElementById("setup-form"); + +form.addEventListener('submit', async e => { + e.preventDefault(); + const username = document.getElementById('username').value; + const email = document.getElementById('email').value; + const password = document.getElementById('password').value; + const admin = true; + + const body = JSON.stringify({username, email, password, admin}); + + const resp = await fetch("/user/register", { + method: "POST", + headers: {'Content-Type': 'application/json'}, + body, + }) + const res = await resp.json(); + if (res.success) location.replace("/user/login"); + else alert("ASJHDOAISJDLKAJSD"); + +}) \ No newline at end of file -- cgit v1.2.3