Files
Siro/backend/transit/admin/logout.php
T

35 lines
1.0 KiB
PHP

<?php
// transit/admin/logout.php — تسجيل خروج مشرف المؤسسة (حذف الجلسة)
// POST: — (التوكن في الهيدر Authorization: Bearer)
require_once __DIR__ . '/../../core/bootstrap.php';
require_once __DIR__ . '/../functions.php';
try { $transit_con = Database::get('transit'); }
catch (Exception $e) { jsonError('Transit service unavailable', 503); }
// استخرج التوكن من الهيدر
$authHeader = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
$token = '';
if (preg_match('/Bearer\s+(\S+)/i', $authHeader, $m)) {
$token = $m[1];
} else {
$token = filterRequest('token') ?? '';
}
if (!$token) jsonError('No session token provided', 400);
$hash = hash('sha256', $token);
// حذف من Redis
if ($redis) $redis->del("siro:transit:session:{$hash}");
// حذف من MySQL
try {
$transit_con->prepare("DELETE FROM transit_sessions WHERE token_hash=?")->execute([$hash]);
} catch (Throwable $e) {
// لا بأس — الجلسة انتهت بالـ Redis
}
jsonSuccess(null, 'Logged out successfully');