integration de password.js à reinitialisation mdp

This commit is contained in:
2025-12-16 08:50:31 +01:00
parent 706d3ece23
commit 55a31a507c
3 changed files with 76 additions and 92 deletions

View File

@@ -1,100 +1,77 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Réinitialisation du mot de passe</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
/>
<style> <head>
body { <meta charset="UTF-8" />
background: #f4f6f981; <meta name="viewport" content="width=device-width, initial-scale=1.0" />
height: 100vh; <title>Réinitialisation du mot de passe</title>
display: flex; <link href="/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
justify-content: center; <link rel="shortcut icon" href="/favicon.png" type="image/png">
align-items: center;
}
.reset-password-card {
width: 100%;
max-width: 380px;
}
</style>
</head>
<body>
<div class="card shadow reset-password-card">
<div class="card-body p-4">
<h1 class="text-center mb-4 fs-3">Nouveau mot de passe</h1>
<p class="text text-muted mb-4">
Pour réinitialiser votre mot de passe, veuillez saisir un nouveau mot
de passe ainsi qu'une confirmation.
</p> <style>
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
<div .reset-password-card {
id="errorMsg" width: 100%;
class="alert alert-danger text-center fs-1" max-width: 380px;
style="display: none" }
> </style>
Les mots de passe ne correspondent pas. </head>
</div>
<form id="resetForm"> <body>
<div class="mb-4">
<label class="form-label"
>Nouveau mot de passe (minimum 8 caractères)</label
>
<input
type="password"
class="form-control"
id="password"
required
/>
<small id="passwordIndicator" class="fw-bold"></small>
</div>
<div class="mb-3"> <div class="card shadow reset-password-card">
<label class="form-label" <div class="card-body p-4">
>Confirmer le mot de passe</label <h1 class="text-center mb-4 fs-3">Nouveau mot de passe</h1>
> <p class="text text-muted mb-4">
<input Pour réinitialiser votre mot de passe, veuillez saisir un nouveau mot
type="password" de passe ainsi qu'une confirmation.
class="form-control"
id="confirmPassword" </p>
required
/>
<label for="showPassword" class="mt-3">
<form id="password-form">
<main>
<div class="mb-4">
<label class="form-label">Nouveau mot de passe <br><span class="small"><span id="min8">8 caractères minimum</span>, incluant une <span id="uppercase">majuscule</span>, une <span id="lowercase">minuscule</span> et un <span id="digit">chiffre</span></span></label>
<input type="password" class="form-control" id="password" required />
</div>
<div class="mb-2">
<label class="form-label">Confirmer le mot de passe</label>
<input type="password" class="form-control" id="passwordConfirm" required />
</div>
<div class="mb-3">
<label for="showPassword" class="mt-3">
<input type="checkbox" id="showPassword" /> <input type="checkbox" id="showPassword" />
Voir le mot de passe Voir le mot de passe
</label> </label>
</div> </div>
<div
id="successMsg"
class="alert alert-success text-center"
style="display: none"
>
Votre mot de passe a été modifié avec succès !
</div>
<button class="btn btn-primary w-100" type="submit">
Changer le mot de passe <button class="btn btn-primary w-100" type="submit">
</button> Changer le mot de passe
<div class="text-center mt-3"> </button>
<a <div class="text-center mt-3">
href="../html/page_de_connexion.html" <a href="../html/page_de_connexion.html" class="text-decoration-none">Retour à la connexion</a>
class="text-decoration-none" </form>
>Retour à la connexion</a </main>
</form> </div>
</div>
</div> </div>
<script src="../js/reinitialisation_du_mot_de_passe.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> <script src="/js/password.js"></script>
</body> </body>
</html> </html>

View File

@@ -40,7 +40,7 @@ form.addEventListener('submit', function(e) {
if (pass.length < minLength) { if (pass.length < minLength) {
errorMsg.style.display = 'block'; errorMsg.style.display = 'block';
errorMsg.textContent = `Le mot de passe doit contenir au moins ${minLength} caractères.`; errorMsg.textContent = `Le mot de passe doit contenir au moins ${minLength} caractères.`;
return; return;8 caractères minimum
} }
//Correspondance //Correspondance
@@ -61,7 +61,7 @@ form.addEventListener('submit', function(e) {
showPasswordCheckbox.addEventListener('change', function() { showPasswordCheckbox.addEventListener('change', function() {
if (this.checked) { if (this.checked) {8 caractères minimum
password.type = 'text'; password.type = 'text';
confirmPassword.type = 'text'; confirmPassword.type = 'text';

View File

@@ -81,10 +81,17 @@ passwordForm.addEventListener('submit', function(event) {
password !== confirmPassword) { password !== confirmPassword) {
event.preventDefault(); event.preventDefault();
const main = document.querySelector('main');
const existingAlert = main.querySelector('#password-alert');
if (existingAlert) {
existingAlert.remove();
}
const alertElt = document.createElement('div'); const alertElt = document.createElement('div');
alertElt.id = 'password-alert';
alertElt.className = 'alert alert-danger text-center'; alertElt.className = 'alert alert-danger text-center';
alertElt.textContent = "Le mot de passe ne respecte pas les critères requis ou la confirmation ne correspond pas."; alertElt.textContent = "Le mot de passe ne respecte pas les critères requis ou la confirmation ne correspond pas.";
document.querySelector('main').prepend(alertElt); main.prepend(alertElt);
window.scrollTo(0, 0); window.scrollTo(0, 0);