draft: dev-web - forgotten password token

This commit is contained in:
kmitresse
2024-03-22 10:53:13 +01:00
parent 1e02ad373c
commit 0e7066808b
9 changed files with 375 additions and 3 deletions
@@ -0,0 +1,26 @@
const forgottenPasswordForm = document.getElementById("forgottenPasswordForm");
forgottenPasswordForm.addEventListener("submit", (event) => {
event.preventDefault();
//Recuperer les données du formulaire
const formData = new FormData(forgottenPasswordForm);
const data = {};
formData.forEach((value, key) => data[key] = value);
//Recuperer l'URL de l'action et la methode
const action = forgottenPasswordForm.getAttribute("action");
const method = forgottenPasswordForm.getAttribute("method");
//Redirection vers le servlet ForgottenPasswordServlet
fetch(action, {
headers: {"Content-Type": "application/json"},
body: JSON.stringify(data),
method,
})
.then(res => res.json())
.then(data => {
console.log(data);
// if (data.status === 200) window.location.href = data.redirect;
})
.catch(error => console.error("Error:", error))
});
@@ -11,6 +11,19 @@
<title>Forgotten Password</title>
</head>
<body>
<main>
<h1>Forgotten Password</h1>
<p>Entrer votre email pour recevoir un lien de récupération</p>
<form id="forgottenPasswordForm" action="forgotten-password" method="post">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<button type="submit">Send</button>
</form>
<%if(request.getParameter("error") != null){%>
<p>L'adresse mail insérée est incorrecte</p>
<%} else if (request.getParameter("success") != null) {%>
<p>Un email vous a été envoyé</p>
<%}%>
</main>
</body>
</html>