mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
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:
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user