fix(DevWeb): Resolve Login and Register functions

This commit is contained in:
Lucàs
2024-04-03 16:45:42 +02:00
parent ff7e2687c2
commit f45b477020
13 changed files with 154 additions and 167 deletions
@@ -7,20 +7,14 @@ loginForm.addEventListener("submit", (event) => {
const data = {};
formData.forEach((value, key) => data[key] = value);
const action = loginForm.getAttribute("action")
const method = loginForm.getAttribute("method")
fetch(action, {
fetch(loginForm.getAttribute("action"), {
headers: {"Content-Type": "application/json"},
body: JSON.stringify(data),
method,
method: loginForm.getAttribute("method"),
})
.then(res => console.log(res))
//.then(data => {
// if (data.status === 200) window.location.href = data.redirect;
//})
.catch(error => console.error("Error:", error))
;
.then(res => res.json())
.then(d => window.location.href = "./main-menu")
.catch(error => console.error("Error:", error));
});
@@ -1,30 +1,21 @@
const registerForm = document.getElementById("register-form");
const confirmPassword = document.getElementById("confirmPassword");
registerForm.addEventListener("submit", function (event) {
registerForm.addEventListener("submit", (event) => {
event.preventDefault();
const formData = new FormData(registerForm);
const data = {};
formData.forEach((value, key) => data[key] = value);
const action = loginForm.getAttribute("action")
const method = loginForm.getAttribute("method")
fetch("/reset-password", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
fetch(registerForm.getAttribute("action"), {
method: registerForm.getAttribute("method"),
headers: {"Content-Type": "application/json"},
body: JSON.stringify(data)
}).then(response => {
if (response.ok) {
window.location.href = "/login";
} else {
response.json().then(data => {
alert(data.message);
});
}
}).catch(error => console.error("Error:", error));
})
.then(res => res.json())
.then(_ => {
window.location.href = "./login"
})
.catch(error => console.error("Error: " + error))
});
@@ -14,7 +14,7 @@
<div class="flex-column register-gap">
<div>
<h1>Register</h1>
<form id="register-form" action="${pageContext.request.contextPath}/register" method="post">
<form id="register-form" action="${pageContext.request.contextPath}/api/auth/register" method="POST">
<label for="email">Email :</label>
<input type="email" id="email" name="email" required>