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,29 +1,30 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Réinitialisation du mot de passe</title> <title>Réinitialisation du mot de passe</title>
<link <link href="/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
rel="stylesheet" <link rel="shortcut icon" href="/favicon.png" type="image/png">
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
/>
<style> <style>
body { body {
background: #f4f6f981;
height: 100vh; height: 100vh;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.reset-password-card { .reset-password-card {
width: 100%; width: 100%;
max-width: 380px; max-width: 380px;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="card shadow reset-password-card"> <div class="card shadow reset-password-card">
<div class="card-body p-4"> <div class="card-body p-4">
<h1 class="text-center mb-4 fs-3">Nouveau mot de passe</h1> <h1 class="text-center mb-4 fs-3">Nouveau mot de passe</h1>
@@ -33,38 +34,21 @@
</p> </p>
<div
id="errorMsg"
class="alert alert-danger text-center fs-1"
style="display: none"
>
Les mots de passe ne correspondent pas.
</div>
<form id="resetForm">
<form id="password-form">
<main>
<div class="mb-4"> <div class="mb-4">
<label class="form-label" <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>
>Nouveau mot de passe (minimum 8 caractères)</label <input type="password" class="form-control" id="password" required />
>
<input
type="password"
class="form-control"
id="password"
required
/>
<small id="passwordIndicator" class="fw-bold"></small>
</div> </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"> <div class="mb-3">
<label class="form-label"
>Confirmer le mot de passe</label
>
<input
type="password"
class="form-control"
id="confirmPassword"
required
/>
<label for="showPassword" class="mt-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
@@ -75,26 +59,19 @@
<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"> <button class="btn btn-primary w-100" type="submit">
Changer le mot de passe Changer le mot de passe
</button> </button>
<div class="text-center mt-3"> <div class="text-center mt-3">
<a <a href="../html/page_de_connexion.html" class="text-decoration-none">Retour à la connexion</a>
href="../html/page_de_connexion.html"
class="text-decoration-none"
>Retour à la connexion</a
</form> </form>
</main>
</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);