diff options
| author | Daniel Hader <[email protected]> | 2026-05-30 10:10:17 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-05-30 10:10:17 -0500 |
| commit | 929be68e691c1c4015fc6874111b19b9f5d68c02 (patch) | |
| tree | ffc4ecb9c63d8dc242c33d69a592dc093dcfd122 /static/main.js | |
| parent | 772c7844c4ca1de632f64eb9428e8e97eea64ac1 (diff) | |
registration page, me endpoint, and minor content tweaks
Diffstat (limited to 'static/main.js')
| -rw-r--r-- | static/main.js | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/static/main.js b/static/main.js index f18cbef..da3a9d3 100644 --- a/static/main.js +++ b/static/main.js @@ -1,5 +1,17 @@ -async function login() { - +async function me() { + const response = await fetch("/me"); + if (response.ok) { + const result = await response.json(); + const span = document.getElementById("logged-in"); + // this is technically a XSS risk (TODO: deal with it) + // in principle it only affects the person who chose their username, but... + span.innerHTML = `Logged in as ${result.username}`; + span.hidden = false; + } else { + document.getElementById("login-links").hidden = false; + console.log("not logged in? No cookie"); + console.log(response); + } } async function fetch_problems() { @@ -9,7 +21,6 @@ async function fetch_problems() { } const result = await response.json(); - console.log(result); const problems_div = document.getElementById("problems"); while (problems_div.firstChild) { @@ -32,12 +43,7 @@ async function fetch_problems() { } async function on_load() { + await me(); await fetch_problems(); - - const login_anchor = document.createElement("a"); - login_anchor.innerText = "Login / Register"; - login_anchor.href="google.com"; - document.getElementById("login-notice").appendChild(login_anchor); - } |
