Update 16 files

- /src/main/resources/templates/create-account.html
- /src/main/resources/templates/my-profile.html
- /src/main/resources/templates/home.html
- /src/main/resources/templates/update-recipe.html
- /src/main/resources/templates/explore.html
- /src/main/resources/templates/public-profile.html
- /src/main/java/com/example/demo/controller/SiteController.java
- /src/main/java/com/example/demo/controller/ProfileController.java
- /src/main/java/com/example/demo/dto/UserDto.java
- /src/main/java/com/example/demo/dto/UpdateProfileDto.java
- /src/main/java/com/example/demo/dto/ProfileDto.java
- /src/main/java/com/example/demo/service/Impl/RecipeServiceImpl.java
- /src/main/java/com/example/demo/service/Impl/UserServiceImpl.java
- /src/main/java/com/example/demo/service/UserService.java
- /src/main/java/com/example/demo/config/SecurityConfig.java
- /src/main/java/com/example/demo/entity/User.java
This commit is contained in:
Madeleine Stamp
2026-04-18 14:08:08 -06:00
parent c2e6722829
commit 659ab79497
16 changed files with 781 additions and 292 deletions
@@ -51,34 +51,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;
}
@@ -86,23 +91,39 @@
username: document.getElementById("username").value,
email: document.getElementById("email").value,
hashedpassword: password,
role: "USER"
role: "ROLE_USER"
};
const csrfToken = document.querySelector('meta[name="_csrf"]').getAttribute('content');
const csrfHeader = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
console.log("JSON to submit:", JSON.stringify(userData, null, 2));
fetch("http://localhost:8080/api/users", {
method: "POST",
headers: {
[csrfHeader]: csrfToken,
'Content-Type': 'application/json'
},
body: JSON.stringify(userData)
});
e.preventDefault();
const csrfToken = document.querySelector('meta[name="_csrf"]').getAttribute('content');
const csrfHeader = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
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);
}
});
});