This commit is contained in:
Ty Clifford
2026-06-30 11:14:42 -04:00
commit 0fe5a92f90
18 changed files with 4775 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
const siteForm = document.querySelector("#publicSignupForm");
const siteResult = document.querySelector("#signupResult");
function showSignupMessage(message) {
if (siteResult) {
siteResult.textContent = message;
}
}
async function siteApi(action, payload) {
const response = await fetch(`/api.php?action=${encodeURIComponent(action)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const json = await response.json();
if (!response.ok || json.error) {
throw new Error(json.error || "Request failed.");
}
return json;
}
if (siteForm) {
siteForm.addEventListener("submit", async (event) => {
event.preventDefault();
const payload = Object.fromEntries(new FormData(siteForm).entries());
showSignupMessage("Creating profile...");
try {
const result = await siteApi("public_signup", payload);
if (result.user?.id) {
localStorage.setItem("nht:userId", String(result.user.id));
}
siteForm.reset();
const adminCopy = result.first_admin ? " You are the first user, so this profile is an admin." : "";
showSignupMessage(`Profile created.${adminCopy} Opening tracker...`);
window.setTimeout(() => {
window.location.href = "/tracker.php";
}, 900);
} catch (error) {
showSignupMessage(error.message);
}
});
}