diff --git a/account/index.html b/account/index.html index b087d06..4bb32ab 100644 --- a/account/index.html +++ b/account/index.html @@ -37,14 +37,14 @@

Please log in before viewing account information

- +
- +
- -

Please ask an SPFN Developer in the discord server for assistance with password resets

+ +

Please ask an SPFN Developer in the discord server for assistance with password resets

diff --git a/js/accounts.js b/js/accounts.js index 0d01209..85b30b2 100644 --- a/js/accounts.js +++ b/js/accounts.js @@ -24,12 +24,19 @@ function loginError(message, code = null) { async function generateToken(username, password) { const credentials = btoa(`${username} ${password}`); - const response = await fetch("https://account.spfn.net/api/v2/oauth2/generate_token", { - method: "GET", - headers: { - "Authorization": `Basic ${credentials}`, - } - }) + let response; + try { + response = await fetch("https://account.spfn.net/api/v2/oauth2/generate_token", { + method: "GET", + headers: { + "Authorization": `Basic ${credentials}`, + } + }) + } catch (err) { + loginError(`Internal Server Error: ${err.message}`) + throw new Error(err); + } + if (!response.ok) { if (response.status == 400) { // Invalid Login loginError("Invalid SFID or Password"); @@ -55,26 +62,19 @@ async function getToken(username, password) { let expiryStr = sessionStorage.getItem("authExpires"); if (expiryStr) { // Expiry exists so token should exist let expiry = new Date(expiryStr); - if (expiry < new Date()) { - console.log("Token Expired - Generating new token") - token = await generateToken(username, password); // Generate Token and Save to Session Storage - } else if (!token) { - console.log("Expiry found but no token wtf? - Generating new token") - token = await generateToken(username, password); // Generate Token and Save to Session Storage - } else { - console.log("Expiry is less than the current Date() and there is a token") + if (expiry < new Date()) { // Expired token + token = await generateToken(username, password); + } else if (!token) { // Expiry Saved but No Token (shouldn't be possible but it'll be caught if it happens) + token = await generateToken(username, password); } - } else { - console.log("No expiry found - Generating new token") - token = await generateToken(username, password); // Generate Token and Save to Session Storage + } else { // Token Never Saved in Session + token = await generateToken(username, password); } return token } function updateUserDataDisplay(data) { - console.log(data) - document.getElementById("display-name").textContent = data["mii"]["name"]; document.getElementById("sfid").textContent = `SFID: ${data["user_id"]}`; @@ -115,6 +115,7 @@ document.getElementById("login").addEventListener("submit", async function(event const password = await document.getElementById("password").value; let token = await getToken(username, password); + if (!token) return; document.getElementById("password").value = ""; @@ -141,11 +142,9 @@ document.getElementById("login").addEventListener("submit", async function(event window.onload = async function() { let expiryStr = sessionStorage.getItem("authExpires"); if (expiryStr) { - console.log("Expiry found") let expiry = new Date(expiryStr); if (expiry > new Date()) { // Hasn't expired - Get user data - console.log("Not expired - Requesting data") let token = sessionStorage.getItem("authToken"); const response = await fetch("https://account.spfn.net/api/v2/users/@me/profile", {