87 lines
3.5 KiB
PHP
87 lines
3.5 KiB
PHP
<?php ob_start(); ?>
|
|
|
|
<div class="d-flex align-items-center gap-3 mb-4">
|
|
<h1 class="h4 mb-0">Mon profil</h1>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 col-lg-4">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php if ($profileSuccess): ?>
|
|
<div class="alert alert-success py-2 small mb-3">Profil mis à jour.</div>
|
|
<?php endif; ?>
|
|
<?php if ($profileError !== ''): ?>
|
|
<div class="alert alert-danger py-2 small mb-3"><?= htmlspecialchars($profileError) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" action="/profile">
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold" for="display_name">Nom affiché</label>
|
|
<input type="text" id="display_name" name="display_name"
|
|
class="form-control"
|
|
value="<?= htmlspecialchars($profileCurrentName) ?>"
|
|
placeholder="Prénom Nom" required>
|
|
<div class="form-text">Affiché comme auteur sur vos articles.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold text-muted">Email</label>
|
|
<input type="text" class="form-control" value="<?= htmlspecialchars(currentUserEmail() ?? '') ?>" disabled>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">Enregistrer</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
$pdo = dbPdo();
|
|
$_profileRoles = [];
|
|
if ($pdo) {
|
|
$st = $pdo->prepare(
|
|
'SELECT r.name, r.label, COALESCE(array_agg(rc.capability) FILTER (WHERE rc.capability IS NOT NULL), \'{}\') AS caps
|
|
FROM user_roles ur
|
|
JOIN roles r ON r.id = ur.role_id
|
|
LEFT JOIN role_capabilities rc ON rc.role_id = r.id
|
|
WHERE ur.user_email = :email
|
|
GROUP BY r.id, r.name, r.label
|
|
ORDER BY r.name'
|
|
);
|
|
$st->execute([':email' => currentUserEmail()]);
|
|
$_profileRoles = $st->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
if (!empty($_profileRoles)): ?>
|
|
<div class="col-md-6 col-lg-8 mt-4 mt-md-0">
|
|
<h2 class="h6 text-muted mb-3">Rôles & droits</h2>
|
|
<?php foreach ($_profileRoles as $_role):
|
|
$_caps = array_filter(
|
|
explode(',', trim((string)$_role['caps'], '{}')),
|
|
static fn ($c) => $c !== ''
|
|
);
|
|
?>
|
|
<div class="card mb-3">
|
|
<div class="card-header d-flex align-items-center gap-2 py-2">
|
|
<strong><?= htmlspecialchars($_role['label']) ?></strong>
|
|
<code class="text-muted small"><?= htmlspecialchars($_role['name']) ?></code>
|
|
</div>
|
|
<?php if (!empty($_caps)): ?>
|
|
<ul class="list-group list-group-flush small">
|
|
<?php foreach ($_caps as $_cap):
|
|
$_label = KNOWN_CAPABILITIES[trim($_cap)] ?? trim($_cap); ?>
|
|
<li class="list-group-item py-1"><?= htmlspecialchars($_label) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else: ?>
|
|
<div class="card-body py-2 small text-muted">Aucun droit associé à ce rôle.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php
|
|
$content = ob_get_clean();
|
|
$title = 'Mon profil';
|
|
include __DIR__ . '/layout.php';
|