csrf_jeton(), csrf_champ() et csrf_verifier() dans inc/auth.php : un jeton par session, comparé par hash_equals, réponse 400 s'il manque ou ne correspond pas. La vérification est appelée en tête de chaque page qui traite un POST — console d'administration (membres, validation, révocation, groupes, services) et pages des membres (profil, mot de passe, inscription, renouvellement d'adhésion) —, et chaque formulaire porte le champ caché. Ajoute aussi e(), l'échappement de sortie à utiliser dans tout nouveau code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V2csyno8m71DJFKYM1vgzV
113 lines
3.8 KiB
PHP
113 lines
3.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../inc/config.php';
|
|
require_once __DIR__ . '/../inc/auth.php';
|
|
require_once __DIR__ . '/../inc/keycloak.php';
|
|
|
|
session_start_safe();
|
|
require_admin();
|
|
|
|
$users = [];
|
|
$kc_error = null;
|
|
|
|
try {
|
|
$users = kc_list_users();
|
|
} catch (Exception $e) {
|
|
$kc_error = $e->getMessage();
|
|
}
|
|
|
|
// Sépare adhérents et inscrits en attente
|
|
$adherents = array_filter($users, fn($u) => in_array(ADHERENT_GROUP, $u['groupNames'], true));
|
|
$pending = array_filter($users, fn($u) => !in_array(ADHERENT_GROUP, $u['groupNames'], true));
|
|
|
|
$title = 'Gestion des membres';
|
|
require __DIR__ . '/../views/layout.php';
|
|
?>
|
|
|
|
<div class="admin-page">
|
|
<div class="page-header">
|
|
<h1>Gestion des membres</h1>
|
|
<div class="admin-nav">
|
|
<a href="/admin/members.php" class="active">Membres</a>
|
|
<a href="/admin/groups.php">Groupes</a>
|
|
<a href="/admin/services.php">Services</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($kc_error): ?>
|
|
<div class="alert alert-error">Erreur Keycloak : <?= htmlspecialchars($kc_error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Inscrits en attente de validation -->
|
|
<section class="card">
|
|
<h2>En attente de validation (<?= count($pending) ?>)</h2>
|
|
<?php if (!$pending): ?>
|
|
<p class="text-muted">Aucun inscrit en attente.</p>
|
|
<?php else: ?>
|
|
<table class="members-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Nom</th><th>Identifiant</th><th>Email</th><th>Groupes</th><th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($pending as $u): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars(trim(($u['firstName'] ?? '') . ' ' . ($u['lastName'] ?? ''))) ?></td>
|
|
<td><?= htmlspecialchars($u['username'] ?? '') ?></td>
|
|
<td><?= htmlspecialchars($u['email'] ?? '') ?></td>
|
|
<td><?= htmlspecialchars(implode(', ', $u['groupNames']) ?: '—') ?></td>
|
|
<td>
|
|
<form method="post" action="/admin/validate.php" style="display:inline">
|
|
<?= csrf_champ() ?>
|
|
<input type="hidden" name="user_id" value="<?= htmlspecialchars($u['id']) ?>">
|
|
<button type="submit" class="btn-primary btn-sm"
|
|
onclick="return confirm('Valider l\'adhésion de <?= htmlspecialchars(addslashes($u['username'] ?? '')) ?> ?')">
|
|
Valider adhésion
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<!-- Adhérents actifs -->
|
|
<section class="card">
|
|
<h2>Adhérents (<?= count($adherents) ?>)</h2>
|
|
<?php if (!$adherents): ?>
|
|
<p class="text-muted">Aucun adhérent.</p>
|
|
<?php else: ?>
|
|
<table class="members-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Nom</th><th>Identifiant</th><th>Email</th><th>Groupes</th><th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($adherents as $u): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars(trim(($u['firstName'] ?? '') . ' ' . ($u['lastName'] ?? ''))) ?></td>
|
|
<td><?= htmlspecialchars($u['username'] ?? '') ?></td>
|
|
<td><?= htmlspecialchars($u['email'] ?? '') ?></td>
|
|
<td><?= htmlspecialchars(implode(', ', $u['groupNames'])) ?></td>
|
|
<td>
|
|
<form method="post" action="/admin/revoke.php" style="display:inline">
|
|
<?= csrf_champ() ?>
|
|
<input type="hidden" name="user_id" value="<?= htmlspecialchars($u['id']) ?>">
|
|
<button type="submit" class="btn-danger btn-sm"
|
|
onclick="return confirm('Révoquer l\'adhésion de <?= htmlspecialchars(addslashes($u['username'] ?? '')) ?> ?')">
|
|
Révoquer
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|
|
|
|
<?php require __DIR__ . '/../views/layout_end.php'; ?>
|