mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-23 15:18:16 +02:00
Feature: Ajout modification du mot de passe dans l'administration
- Ajout bouton 🔑 Mot de passe pour chaque utilisateur
- Fonction changeUserPassword avec confirmation du mot de passe
- Validation de longueur minimum (6 caractères)
- Double saisie pour confirmation
- Utilisation de la route PUT /api/users/:id existante
- Style bleu pour le bouton d'édition
- Event delegation pour le nouveau bouton
- Permet aux admins de changer leur propre mot de passe
This commit is contained in:
2 files changed
+55
-4
No files matched your search
@@ -509,15 +509,29 @@
|
|||||||
background: var(--color-background);
|
background: var(--color-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-edit-user,
|
||||||
.btn-delete-user {
|
.btn-delete-user {
|
||||||
padding: var(--spacing-sm) var(--spacing-md);
|
padding: var(--spacing-sm) var(--spacing-md);
|
||||||
background: var(--color-danger);
|
|
||||||
color: white;
|
color: white;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
transition: all var(--transition-speed);
|
transition: all var(--transition-speed);
|
||||||
|
margin-right: var(--spacing-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-edit-user {
|
||||||
|
background: var(--color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-edit-user:hover {
|
||||||
|
background: #2980b9;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-delete-user {
|
||||||
|
background: var(--color-danger);
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-delete-user:hover {
|
.btn-delete-user:hover {
|
||||||
|
|||||||
@@ -692,11 +692,14 @@ function renderUsersTable(users) {
|
|||||||
<td>${user.is_admin ? '✓ Oui' : '✗ Non'}</td>
|
<td>${user.is_admin ? '✓ Oui' : '✗ Non'}</td>
|
||||||
<td>${new Date(user.created_at).toLocaleDateString('fr-FR')}</td>
|
<td>${new Date(user.created_at).toLocaleDateString('fr-FR')}</td>
|
||||||
<td>
|
<td>
|
||||||
|
<button class="btn-edit-user" data-user-id="${user.id}" data-username="${escapeHtml(user.username)}">
|
||||||
|
🔑 Mot de passe
|
||||||
|
</button>
|
||||||
${user.id !== state.user.id ? `
|
${user.id !== state.user.id ? `
|
||||||
<button class="btn-delete-user" data-user-id="${user.id}" data-username="${escapeHtml(user.username)}">
|
<button class="btn-delete-user" data-user-id="${user.id}" data-username="${escapeHtml(user.username)}">
|
||||||
🗑️ Supprimer
|
🗑️ Supprimer
|
||||||
</button>
|
</button>
|
||||||
` : '<span style="color: var(--text-secondary);">Vous-même</span>'}
|
` : ''}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`).join('');
|
`).join('');
|
||||||
@@ -756,6 +759,32 @@ async function createUser() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function changeUserPassword(id, username) {
|
||||||
|
const password = prompt(`Nouveau mot de passe pour "${username}" :`);
|
||||||
|
|
||||||
|
if (!password) return;
|
||||||
|
|
||||||
|
if (password.length < 6) {
|
||||||
|
alert('Le mot de passe doit contenir au moins 6 caractères');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmPassword = prompt('Confirmer le nouveau mot de passe :');
|
||||||
|
|
||||||
|
if (password !== confirmPassword) {
|
||||||
|
alert('Les mots de passe ne correspondent pas');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await api.put(`/api/users/${id}`, { password });
|
||||||
|
alert('Mot de passe modifié avec succès');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur modification mot de passe:', error);
|
||||||
|
alert('Erreur lors de la modification du mot de passe');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteUser(id, username) {
|
async function deleteUser(id, username) {
|
||||||
const confirmed = await confirmDialog.show({
|
const confirmed = await confirmDialog.show({
|
||||||
icon: '⚠️',
|
icon: '⚠️',
|
||||||
@@ -899,11 +928,19 @@ async function init() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event delegation pour les boutons de suppression d'utilisateurs
|
// Event delegation pour les boutons d'administration des utilisateurs
|
||||||
const usersTableBody = document.getElementById('usersTableBody');
|
const usersTableBody = document.getElementById('usersTableBody');
|
||||||
if (usersTableBody) {
|
if (usersTableBody) {
|
||||||
usersTableBody.addEventListener('click', (e) => {
|
usersTableBody.addEventListener('click', (e) => {
|
||||||
if (e.target.classList.contains('btn-delete-user') || e.target.closest('.btn-delete-user')) {
|
// Bouton changer mot de passe
|
||||||
|
if (e.target.classList.contains('btn-edit-user') || e.target.closest('.btn-edit-user')) {
|
||||||
|
const btn = e.target.classList.contains('btn-edit-user') ? e.target : e.target.closest('.btn-edit-user');
|
||||||
|
const userId = parseInt(btn.dataset.userId);
|
||||||
|
const username = btn.dataset.username;
|
||||||
|
changeUserPassword(userId, username);
|
||||||
|
}
|
||||||
|
// Bouton supprimer utilisateur
|
||||||
|
else if (e.target.classList.contains('btn-delete-user') || e.target.closest('.btn-delete-user')) {
|
||||||
const btn = e.target.classList.contains('btn-delete-user') ? e.target : e.target.closest('.btn-delete-user');
|
const btn = e.target.classList.contains('btn-delete-user') ? e.target : e.target.closest('.btn-delete-user');
|
||||||
const userId = parseInt(btn.dataset.userId);
|
const userId = parseInt(btn.dataset.userId);
|
||||||
const username = btn.dataset.username;
|
const username = btn.dataset.username;
|
||||||
|
|||||||
Reference in new issue
Block a user