40 lines
1.6 KiB
PHP
40 lines
1.6 KiB
PHP
<?php
|
|
// ============================================================
|
|
// food/connect_app.php — بوابة الزبون (تبويب «طعام» داخل siro_rider)
|
|
// يستخدم JWT الرئيسي نفسه — الزبون هو الراكب نفسه، لا حساب ثانٍ
|
|
// ============================================================
|
|
|
|
require_once __DIR__ . '/../core/bootstrap.php';
|
|
require_once __DIR__ . '/../functions.php';
|
|
require_once __DIR__ . '/functions.php';
|
|
|
|
if (getenv('FOOD_ENABLED') === 'false') {
|
|
http_response_code(503);
|
|
echo json_encode(['status' => 'failure', 'message' => 'Food service is currently disabled']);
|
|
exit;
|
|
}
|
|
|
|
// Rate limiting — نفس حد API العادي
|
|
$limiter = new RateLimiter($redis);
|
|
$limiter->enforce(RateLimiter::identifier(), 'api');
|
|
|
|
// JWT المعتاد — راكب فقط (لا يُقبل توكن سائق هنا)
|
|
$jwtService = new JwtService($redis);
|
|
$decoded = $jwtService->authenticate();
|
|
|
|
if (($decoded->role ?? '') !== 'passenger') {
|
|
jsonError('Forbidden — passenger token required', 403);
|
|
}
|
|
$food_passenger_id = (string)($decoded->user_id ?? '');
|
|
|
|
// اتصال قاعدة بيانات food فقط — ممنوع Database::get('main') في ملفات food/
|
|
try {
|
|
$food_con = Database::get('food');
|
|
} catch (Exception $e) {
|
|
// السبب الحقيقي في اللوج فقط — الرد يبقى عاماً.
|
|
error_log('[FOOD] DB connection failed in ' . basename(__FILE__) . ': ' . $e->getMessage());
|
|
http_response_code(503);
|
|
echo json_encode(['status' => 'failure', 'message' => 'Food service unavailable']);
|
|
exit;
|
|
}
|