feat: rôles admin/user, page Utilisateurs, lien Vision dans navbar, filtre courriers par compte

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jules
2026-05-06 00:01:39 +02:00
parent d11e6aec5e
commit 3f73421fd3
8 changed files with 305 additions and 28 deletions

View File

@@ -15,13 +15,23 @@ function auth_check(): void {
}
}
function admin_check(): void {
auth_check();
if ($_SESSION['admin_role'] !== 'admin') {
header('Location: /');
exit;
}
}
function auth_login(string $username, string $password): bool {
$st = db()->prepare('SELECT id, password FROM admin_users WHERE username = ? LIMIT 1');
$st = db()->prepare('SELECT id, role, account_id, password FROM admin_users WHERE username = ? LIMIT 1');
$st->execute([$username]);
$row = $st->fetch();
if ($row && password_verify($password, $row['password'])) {
$_SESSION['admin_id'] = $row['id'];
$_SESSION['admin_user'] = $username;
$_SESSION['admin_id'] = $row['id'];
$_SESSION['admin_user'] = $username;
$_SESSION['admin_role'] = $row['role'];
$_SESSION['admin_account_id'] = $row['account_id'];
return true;
}
return false;
@@ -34,6 +44,9 @@ function auth_logout(): void {
exit;
}
function current_user(): string {
return $_SESSION['admin_user'] ?? '';
function current_user(): string { return $_SESSION['admin_user'] ?? ''; }
function is_admin(): bool { return ($_SESSION['admin_role'] ?? '') === 'admin'; }
function current_account_id(): ?int {
$id = $_SESSION['admin_account_id'] ?? null;
return $id ? (int)$id : null;
}