From 772c7844c4ca1de632f64eb9428e8e97eea64ac1 Mon Sep 17 00:00:00 2001 From: Daniel Hader Date: Fri, 29 May 2026 18:14:31 -0500 Subject: login page interaction with server --- static/login.html | 18 +++++++++++------- static/login.js | 38 ++++++++++++++++++++++++++++++++++++++ static/main.js | 3 --- 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 static/login.js (limited to 'static') diff --git a/static/login.html b/static/login.html index 37035dc..c6cd992 100644 --- a/static/login.html +++ b/static/login.html @@ -5,21 +5,25 @@ Code Golf Login - + - +

C&! Code Golf Leaderboard

Login

-
-
- + + +
+

-
- +
+

diff --git a/static/login.js b/static/login.js new file mode 100644 index 0000000..ee135f8 --- /dev/null +++ b/static/login.js @@ -0,0 +1,38 @@ + +function display_error(message) { + document.getElementById("error-message").innerHTML = `Error: ${message}`; + document.getElementById("error").hidden = false; +} + +function init() { + const form = document.getElementById("login-form"); + form.addEventListener("submit", async (e) => { + e.preventDefault(); + + const body = {} + new FormData(form).forEach((value, key) => body[key] = value); + + try { + console.log(); + + const res = await fetch("/login", { + method: "POST", + headers: { "Content-Type": "application/json" }, + credentials: "include", + body: JSON.stringify(body) + }); + + if (!res.ok) { + const error = await res.json(); + display_error(error.error); + return; + } + + //const result = await res.json(); + + } catch (err) { + console.log(err); + //display_error("network error"); + } + }); +} diff --git a/static/main.js b/static/main.js index 2bde100..f18cbef 100644 --- a/static/main.js +++ b/static/main.js @@ -41,6 +41,3 @@ async function on_load() { } -async function login() { - console.log("login pressed"); -} -- cgit v1.2.3