From 343de86101951c857b74c27cb54f0362b7b0219e Mon Sep 17 00:00:00 2001 From: KittenTM Date: Fri, 6 Feb 2026 23:01:30 +0100 Subject: [PATCH] implement auto-login on login page --- .gitignore | 1 + config.js | 2 +- config_example.js | 3 ++ users/auth/splatfestival/index.html | 30 +---------- users/auth/splatfestival/splatfestivalyay.js | 52 +++++++++++++++----- 5 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 config_example.js diff --git a/.gitignore b/.gitignore index c67375c..d82db84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pem server.py +config.js \ No newline at end of file diff --git a/config.js b/config.js index b6dca06..59a9504 100644 --- a/config.js +++ b/config.js @@ -1,4 +1,4 @@ // note: this is just the default config const CONFIG = { - API_BASE_URL: "http://127.0.0.1:5000" + API_BASE_URL: "http://192.168.1.177:5000" }; \ No newline at end of file diff --git a/config_example.js b/config_example.js new file mode 100644 index 0000000..920f71c --- /dev/null +++ b/config_example.js @@ -0,0 +1,3 @@ +const CONFIG = { + API_BASE_URL: "backendurl" +}; \ No newline at end of file diff --git a/users/auth/splatfestival/index.html b/users/auth/splatfestival/index.html index 07aa727..beca97f 100644 --- a/users/auth/splatfestival/index.html +++ b/users/auth/splatfestival/index.html @@ -59,7 +59,7 @@
- +
@@ -71,39 +71,13 @@ - - \ No newline at end of file diff --git a/users/auth/splatfestival/splatfestivalyay.js b/users/auth/splatfestival/splatfestivalyay.js index 19a336c..5410a0b 100644 --- a/users/auth/splatfestival/splatfestivalyay.js +++ b/users/auth/splatfestival/splatfestivalyay.js @@ -1,17 +1,43 @@ -window.onload = function() { +$(document).ready(function () { + const form = $("#auth-form"); + const errorContainer = $("#auth-error"); const urlParams = new URLSearchParams(window.location.search); + const apiBase = CONFIG.API_BASE_URL; - if (urlParams.has('error')) { - const errorContainer = document.getElementById("auth-error"); - if (errorContainer) { - errorContainer.textContent = "Invalid SFID or Password"; - errorContainer.style.display = "block"; // Show the red text - } - - //user convenience.....grrr - const userField = document.getElementsByName("username")[0]; - if (userField && urlParams.has('username')) { - userField.value = urlParams.get('username'); + $("#frontend_origin").val(window.location.origin); + + form.attr("action", apiBase + "/api/v2/sso/spfn/generate_token"); + + async function checkExistingSession() { + try { + const response = await fetch(apiBase + "/api/v1/users/me", { + method: 'GET', + credentials: 'include' + }); + if (response.ok) { + window.location.href = "/friend_list/"; + } + } catch (err) { + console.log("auth check failed"); } } -} \ No newline at end of file + + if (!urlParams.has('error')) { + checkExistingSession(); + } + + if (urlParams.has('error')) { + errorContainer.text("Invalid SFID or Password").show(); + if (urlParams.has('username')) { + $("input[name='username']").val(urlParams.get('username')); + } + } + + form.submit(function() { + const submitBtn = $(":submit", this); + submitBtn.prop("disabled", true).val("Signing In..."); + setTimeout(function() { + submitBtn.prop("disabled", false).val("Sign In"); + }, 10000); + }); +}); \ No newline at end of file