mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
Unify flash messages: replace all legacy session key writes with App::flash()
All admin action files (account, tag, page, edit, visibility, maintenance,
publish, formulaire) now call App::flash('error'|'success', ...) instead of
writing to raw per-page session keys ($_SESSION['error'], 'admin_error',
'edit_error', 'admin_success', 'edit_success', 'form_error').
All admin display pages (add, edit, account, tags, pages, index) now include
templates/partials/flash-messages.php instead of manually reading and
unsetting the legacy session keys and inlining their own alert HTML.
App::consumeFlash() already drained all legacy key variants as a safety net,
so the partial works correctly whether called from pages that were already
migrated or any remaining stragglers. No behaviour change for end users.
This commit is contained in:
@@ -24,13 +24,13 @@ $action = $_POST['action'] ?? 'change_password';
|
||||
// ── Remove credentials ────────────────────────────────────────────────────────
|
||||
if ($action === 'remove_credentials') {
|
||||
if (!$hasPassword) {
|
||||
$_SESSION['error'] = 'Aucun fichier de mot de passe à supprimer.';
|
||||
App::flash('error', 'Aucun fichier de mot de passe à supprimer.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_writable($credentialsFile) && !is_writable(dirname($credentialsFile))) {
|
||||
$_SESSION['error'] = 'Le fichier de configuration n\'est pas accessible en écriture.';
|
||||
App::flash('error', 'Le fichier de configuration n\'est pas accessible en écriture.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ if ($action === 'remove_credentials') {
|
||||
header('Location: /admin/login.php');
|
||||
exit;
|
||||
} else {
|
||||
$_SESSION['error'] = 'Impossible de supprimer le fichier de configuration.';
|
||||
App::flash('error', 'Impossible de supprimer le fichier de configuration.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ if ($action === 'remove_credentials') {
|
||||
if ($hasPassword) {
|
||||
$currentPassword = $_POST['current_password'] ?? '';
|
||||
if (!AdminAuth::login($currentPassword)) {
|
||||
$_SESSION['error'] = 'Mot de passe actuel incorrect.';
|
||||
App::flash('error', 'Mot de passe actuel incorrect.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
@@ -64,13 +64,13 @@ $newPassword = $_POST['new_password'] ?? '';
|
||||
$confirmPassword = $_POST['confirm_password'] ?? '';
|
||||
|
||||
if (strlen($newPassword) < 12) {
|
||||
$_SESSION['error'] = 'Le nouveau mot de passe doit contenir au moins 12 caractères.';
|
||||
App::flash('error', 'Le nouveau mot de passe doit contenir au moins 12 caractères.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($newPassword !== $confirmPassword) {
|
||||
$_SESSION['error'] = 'Les mots de passe ne correspondent pas.';
|
||||
App::flash('error', 'Les mots de passe ne correspondent pas.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ if ($newPassword !== $confirmPassword) {
|
||||
// 3. Generate bcrypt hash (cost 12).
|
||||
$hash = password_hash($newPassword, PASSWORD_BCRYPT, ['cost' => 12]);
|
||||
if ($hash === false) {
|
||||
$_SESSION['error'] = 'Erreur lors du hachage du mot de passe.';
|
||||
App::flash('error', 'Erreur lors du hachage du mot de passe.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
@@ -99,13 +99,13 @@ $configContent = '<?php' . "\n"
|
||||
$tmpFile = $credentialsFile . '.tmp.' . bin2hex(random_bytes(6));
|
||||
if (file_put_contents($tmpFile, $configContent, LOCK_EX) === false) {
|
||||
@unlink($tmpFile);
|
||||
$_SESSION['error'] = 'Impossible d\'écrire le fichier de configuration. Vérifiez les permissions sur config/.';
|
||||
App::flash('error', 'Impossible d\'écrire le fichier de configuration. Vérifiez les permissions sur config/.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
if (!rename($tmpFile, $credentialsFile)) {
|
||||
@unlink($tmpFile);
|
||||
$_SESSION['error'] = 'Impossible de mettre à jour le fichier de configuration.';
|
||||
App::flash('error', 'Impossible de mettre à jour le fichier de configuration.');
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
}
|
||||
@@ -114,9 +114,9 @@ if (!rename($tmpFile, $credentialsFile)) {
|
||||
session_regenerate_id(true);
|
||||
$_SESSION['admin_authenticated'] = true;
|
||||
|
||||
$_SESSION['success'] = $hasPassword
|
||||
App::flash('success', $hasPassword
|
||||
? 'Mot de passe mis à jour avec succès.'
|
||||
: 'Mot de passe défini avec succès. L\'authentification PHP est maintenant active.';
|
||||
: 'Mot de passe défini avec succès. L\'authentification PHP est maintenant active.');
|
||||
|
||||
header('Location: /admin/account.php');
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user