mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
Functional Verification
This commit is contained in:
@@ -146,27 +146,25 @@ function isProfane(str) {
|
||||
const csrfHeader = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/users", {
|
||||
sessionStorage.setItem("pendingEmail", email);
|
||||
sessionStorage.setItem("pendingUser", JSON.stringify({
|
||||
username: name,
|
||||
email: email,
|
||||
hashedpassword: password,
|
||||
role: "ROLE_USER"
|
||||
}));
|
||||
|
||||
await fetch(`/api/email/send?email=${encodeURIComponent(email)}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
[csrfHeader]: csrfToken,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
headers: { [csrfHeader]: csrfToken }
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
passwordError.style.color = "green";
|
||||
passwordError.textContent = "Check your email for a verification code...";
|
||||
setTimeout(function () {
|
||||
window.location.href = "/verify";
|
||||
}, 1500);
|
||||
|
||||
} catch (error) {
|
||||
passwordError.style.color = "red";
|
||||
passwordError.textContent = "Could not connect to the server.";
|
||||
|
||||
Reference in New Issue
Block a user