feat: bouton édition compte (nom affiché, webhook, mot de passe)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
header('Location: /admin/accounts.php');
|
header('Location: /admin/accounts.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($_POST['action'] === 'edit') {
|
||||||
|
$id = (int)$_POST['account_id'];
|
||||||
|
$display = trim($_POST['display_name'] ?? '');
|
||||||
|
$webhook = trim($_POST['webhook_url'] ?? '');
|
||||||
|
$newPassword = trim($_POST['new_password'] ?? '');
|
||||||
|
|
||||||
|
db()->prepare('UPDATE accounts SET display_name = ?, webhook_url = ? WHERE id = ?')
|
||||||
|
->execute([$display ?: null, $webhook ?: null, $id]);
|
||||||
|
|
||||||
|
if (strlen($newPassword) >= 6) {
|
||||||
|
$st = db()->prepare('SELECT username FROM accounts WHERE id = ?');
|
||||||
|
$st->execute([$id]);
|
||||||
|
$row = $st->fetch();
|
||||||
|
if ($row) {
|
||||||
|
$domain = cfg('domain');
|
||||||
|
$hash = shell_exec(sprintf('doveadm pw -s SHA512-CRYPT -p %s', escapeshellarg($newPassword)));
|
||||||
|
$hash = trim($hash ?? '');
|
||||||
|
if ($hash) {
|
||||||
|
shell_exec(sprintf(
|
||||||
|
"sed -i 's|^%s@%s:.*|%s@%s:%s:::|' /etc/dovecot/users",
|
||||||
|
$row['username'], $domain,
|
||||||
|
$row['username'], $domain, $hash
|
||||||
|
));
|
||||||
|
$smbUser = $row['username'];
|
||||||
|
shell_exec(sprintf('(echo %s; echo %s) | smbpasswd -s %s 2>/dev/null',
|
||||||
|
escapeshellarg($newPassword), escapeshellarg($newPassword), escapeshellarg($smbUser)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flash('success', "Compte mis à jour.");
|
||||||
|
header('Location: /admin/accounts.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$accounts = db()->query(
|
$accounts = db()->query(
|
||||||
@@ -183,6 +219,11 @@ html_navbar('accounts');
|
|||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
|
<div class="d-flex gap-1 justify-content-center">
|
||||||
|
<button class="btn btn-sm btn-outline-secondary" title="Modifier"
|
||||||
|
onclick="openEdit(<?= $acc['id'] ?>, '<?= htmlspecialchars(addslashes($acc['display_name'] ?? ''), ENT_QUOTES) ?>', '<?= htmlspecialchars(addslashes($acc['webhook_url'] ?? ''), ENT_QUOTES) ?>', '<?= htmlspecialchars($acc['username']) ?>')">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</button>
|
||||||
<form method="post" onsubmit="return confirm('Supprimer le compte <?= htmlspecialchars($acc['username']) ?> et tous ses fichiers ?')">
|
<form method="post" onsubmit="return confirm('Supprimer le compte <?= htmlspecialchars($acc['username']) ?> et tous ses fichiers ?')">
|
||||||
<input type="hidden" name="action" value="delete">
|
<input type="hidden" name="action" value="delete">
|
||||||
<input type="hidden" name="account_id" value="<?= $acc['id'] ?>">
|
<input type="hidden" name="account_id" value="<?= $acc['id'] ?>">
|
||||||
@@ -190,6 +231,7 @@ html_navbar('accounts');
|
|||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -201,4 +243,49 @@ html_navbar('accounts');
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Modal édition -->
|
||||||
|
<div class="modal fade" id="editModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="action" value="edit">
|
||||||
|
<input type="hidden" name="account_id" id="edit-id">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title"><i class="bi bi-pencil me-2"></i>Modifier le compte <strong id="edit-username"></strong></h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Nom affiché</label>
|
||||||
|
<input type="text" name="display_name" id="edit-display" class="form-control" placeholder="Nom affiché">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Webhook URL</label>
|
||||||
|
<input type="url" name="webhook_url" id="edit-webhook" class="form-control" placeholder="https://…/webhook">
|
||||||
|
<div class="form-text">POST JSON à chaque réception. Laisser vide pour désactiver.</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Nouveau mot de passe <span class="text-muted">(laisser vide pour ne pas changer)</span></label>
|
||||||
|
<input type="password" name="new_password" id="edit-password" class="form-control" minlength="6" placeholder="••••••">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Annuler</button>
|
||||||
|
<button type="submit" class="btn btn-primary"><i class="bi bi-floppy-fill me-1"></i>Enregistrer</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function openEdit(id, display, webhook, username) {
|
||||||
|
document.getElementById('edit-id').value = id;
|
||||||
|
document.getElementById('edit-username').textContent = username;
|
||||||
|
document.getElementById('edit-display').value = display;
|
||||||
|
document.getElementById('edit-webhook').value = webhook;
|
||||||
|
document.getElementById('edit-password').value = '';
|
||||||
|
new bootstrap.Modal(document.getElementById('editModal')).show();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<?php html_foot(); ?>
|
<?php html_foot(); ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user