-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_password.html
More file actions
205 lines (186 loc) · 10.4 KB
/
Copy pathchange_password.html
File metadata and controls
205 lines (186 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Changer le mot de passe</title>
<link rel="stylesheet" href="global.css?v=1.1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="change_password.css?v=1.1">
</head>
<body class="dashboard-body">
<div class="container-change-password" style="max-width: 600px;">
<div class="header-title-group">
<h2>Changement de Mot de Passe</h2>
</div>
<div class="action-buttons">
<a href="dashboard.html" class="back-btn">
<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
Dashboard
</a>
</div>
<div id="change-password-form-container">
<div id="error-msg" class="error-message" style="display:none; color: #e74c3c; background: rgba(231, 76, 60, 0.1); padding: 10px; border-radius: 5px; margin-bottom: 15px; text-align: center; border: 1px solid #e74c3c;"></div>
<div id="success-msg" class="success-message" style="display:none; color: #2ecc71; background: rgba(46, 204, 113, 0.1); padding: 10px; border-radius: 5px; margin-bottom: 15px; text-align: center; border: 1px solid #2ecc71;"></div>
<form id="profile-form">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
<div class="form-group">
<label for="profile-username">Pseudo</label>
<div class="password-wrapper">
<i class="fas fa-user input-icon"></i>
<input type="text" id="profile-username" required style="padding-right: 15px;">
</div>
</div>
<div class="form-group">
<label for="profile-email">Email</label>
<div class="password-wrapper">
<i class="fas fa-envelope input-icon"></i>
<input type="email" id="profile-email" required style="padding-right: 15px;">
</div>
</div>
<div class="form-group">
<label for="profile-telephone">Téléphone</label>
<div class="password-wrapper">
<i class="fas fa-phone input-icon"></i>
<input type="tel" id="profile-telephone" style="padding-right: 15px;">
</div>
</div>
</div>
<div style="margin-top: 20px; border-top: 1px solid #4a4a4a; padding-top: 15px;">
<h3 style="color: #0077b3; margin-bottom: 15px; font-size: 1.1em;">Changer le mot de passe (optionnel)</h3>
<div class="form-group">
<label for="current-password">Mot de passe actuel (requis pour toute modification)</label>
<div class="password-wrapper">
<i class="fas fa-lock input-icon"></i>
<input type="password" id="current-password" required>
<span class="toggle-password" data-target="current-password">👁️</span>
</div>
</div>
<div class="form-group">
<label for="new-password">Nouveau mot de passe</label>
<div class="password-wrapper">
<i class="fas fa-key input-icon"></i>
<input type="password" id="new-password" minlength="6">
<span class="toggle-password" data-target="new-password">👁️</span>
</div>
</div>
<div class="form-group">
<label for="confirm-password">Confirmer le nouveau mot de passe</label>
<div class="password-wrapper">
<i class="fas fa-key input-icon"></i>
<input type="password" id="confirm-password" minlength="6">
<span class="toggle-password" data-target="confirm-password">👁️</span>
</div>
</div>
</div>
<div class="form-actions" style="display: flex; gap: 10px; justify-content: center; margin-top: 20px;">
<button type="submit" class="btn-ok">Enregistrer les modifications</button>
<button type="button" class="btn-cancel" onclick="window.location.href='dashboard.html'">Annuler</button>
</div>
</form>
</div>
<footer class="main-footer">
<p>© 2025 HardLink - Tous droits réservés</p>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const currentUser = JSON.parse(localStorage.getItem('currentUser'));
if (!currentUser) {
window.location.href = 'index.html';
return;
}
// Pré-remplir les champs avec les données actuelles
document.getElementById('profile-username').value = currentUser.username || '';
document.getElementById('profile-email').value = currentUser.email || '';
document.getElementById('profile-telephone').value = currentUser.telephone || '';
const form = document.getElementById('profile-form');
const errorMsg = document.getElementById('error-msg');
const successMsg = document.getElementById('success-msg');
// Toggle Password Visibility
document.querySelectorAll('.toggle-password').forEach(span => {
span.addEventListener('click', function() {
const targetId = this.getAttribute('data-target');
const passwordInput = document.getElementById(targetId);
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
this.textContent = '🙈';
} else {
passwordInput.type = 'password';
this.textContent = '👁️';
}
});
});
form.addEventListener('submit', function(e) {
e.preventDefault();
const username = document.getElementById('profile-username').value;
const email = document.getElementById('profile-email').value;
const telephone = document.getElementById('profile-telephone').value;
const currentPassword = document.getElementById('current-password').value;
const newPassword = document.getElementById('new-password').value;
const confirmPassword = document.getElementById('confirm-password').value;
errorMsg.style.display = 'none';
successMsg.style.display = 'none';
if (newPassword && newPassword !== confirmPassword) {
errorMsg.textContent = 'Les nouveaux mots de passe ne correspondent pas.';
errorMsg.style.display = 'block';
return;
}
if (newPassword && newPassword === currentPassword) {
errorMsg.textContent = 'Le nouveau mot de passe doit être différent de l\'ancien.';
errorMsg.style.display = 'block';
return;
}
fetch('api/change_password.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
userId: currentUser.id,
username: username,
email: email,
telephone: telephone,
currentPassword: currentPassword,
newPassword: newPassword || null
})
})
.then(response => response.json())
.then(data => {
console.log('Réponse de l\'API:', data);
if (data.success) {
// Mettre à jour le localStorage avec les nouvelles données (sauf le mot de passe)
currentUser.username = username;
currentUser.email = email;
currentUser.telephone = telephone;
localStorage.setItem('currentUser', JSON.stringify(currentUser));
if (newPassword) {
alert('Profil et mot de passe mis à jour avec succès ! Vous allez être redirigé vers la page de connexion.');
localStorage.removeItem('currentUser');
window.location.href = 'index.html';
} else {
successMsg.textContent = 'Profil mis à jour avec succès !';
successMsg.style.display = 'block';
// Vider le champ mot de passe actuel
document.getElementById('current-password').value = '';
// Optionnel : redirection vers dashboard après un court délai
setTimeout(() => {
window.location.href = 'dashboard.html';
}, 2000);
}
} else {
errorMsg.textContent = data.message;
errorMsg.style.display = 'block';
}
})
.catch(error => {
console.error('Erreur:', error);
errorMsg.textContent = 'Une erreur est survenue lors de la modification du profil.';
errorMsg.style.display = 'block';
});
});
});
</script>
<script src="js/auth_check.js"></script>
</body>
</html>