Init Git Prod Mars 2026
This commit is contained in:
commit
d81efe93b1
362 files changed
+86627
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) session_start();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../public/includes/init_pr_cl.php';
|
||||
|
||||
|
||||
$PUSHCFG = require __DIR__ . '/config.php';
|
||||
|
||||
function json_response(array $data, int $status = 200): never {
|
||||
http_response_code($status);
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auth JSON (pas de redirect HTML)
|
||||
*/
|
||||
function require_auth_json(?array $roles = null): void {
|
||||
if (!is_logged_in()) {
|
||||
json_response(['ok'=>false, 'error'=>'auth_required'], 401);
|
||||
}
|
||||
if ($roles) {
|
||||
$role = strtolower((string)($_SESSION['role'] ?? ''));
|
||||
$allowed = array_map(fn($r)=>strtolower((string)$r), $roles);
|
||||
if (!in_array($role, $allowed, true)) {
|
||||
json_response(['ok'=>false, 'error'=>'forbidden'], 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function read_json_body(): array {
|
||||
$raw = file_get_contents('php://input');
|
||||
if (!$raw) return [];
|
||||
$data = json_decode($raw, true);
|
||||
return is_array($data) ? $data : [];
|
||||
}
|
||||
Reference in new issue
Block a user