Merge branch 'main' of gitlab.com:etc404/software-engineering-project

i didn't commit my decorative changes before create-html was updated
sorry
This commit is contained in:
kaipher7
2026-04-18 23:51:59 -06:00
23 changed files with 968 additions and 142 deletions
@@ -2,6 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta charset="UTF-8">
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
<meta name="_csrf" th:content="${_csrf.token}"/>
<title>Create Thyme Crunch Account</title>
<link rel="stylesheet" th:href="@{css/create-account.css}">
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
@@ -57,34 +60,39 @@
<script>
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("createUserForm");
const passwordField = document.getElementById("password");
const confirmPasswordField = document.getElementById("confirmPassword");
const passwordError = document.getElementById("passwordError");
function checkPasswords() {
if (confirmPasswordField.value === "") {
confirmPasswordField.classList.remove("invalid");
passwordError.textContent = "";
return;
}
if (passwordField.value !== confirmPasswordField.value) {
confirmPasswordField.classList.add("invalid");
passwordError.textContent = "Passwords do not match.";
} else {
confirmPasswordField.classList.remove("invalid");
passwordError.textContent = "";
}
}
passwordField.addEventListener("input", checkPasswords);
confirmPasswordField.addEventListener("input", checkPasswords);
document.getElementById("createUserForm").addEventListener("submit", function(e) {
form.addEventListener("submit", async function(e) {
e.preventDefault();
const password = passwordField.value;
const confirmPassword = confirmPasswordField.value;
if (password !== confirmPassword) {
e.preventDefault();
confirmPasswordField.classList.add("invalid");
passwordError.textContent = "Passwords do not match.";
return;
}
@@ -92,18 +100,39 @@
username: document.getElementById("username").value,
email: document.getElementById("email").value,
hashedpassword: password,
role: "USER"
role: "ROLE_USER"
};
fetch("http://localhost:8080/api/users", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(userData)
});
const csrfToken = document.querySelector('meta[name="_csrf"]').getAttribute('content');
const csrfHeader = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
e.preventDefault();
try {
const response = await fetch("/api/users", {
method: "POST",
headers: {
[csrfHeader]: csrfToken,
"Content-Type": "application/json"
},
body: JSON.stringify(userData)
});
if (response.ok) {
passwordError.style.color = "green";
passwordError.textContent = "Account created successfully. Redirecting to login...";
setTimeout(function () {
window.location.href = "/login";
}, 1500);
} else {
const errorText = await response.text();
passwordError.style.color = "red";
passwordError.textContent = "Account creation failed. Please try a different username or email.";
console.error("Create account failed:", errorText);
}
} catch (error) {
passwordError.style.color = "red";
passwordError.textContent = "Could not connect to the server.";
console.error("Request error:", error);
}
});
});