42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
// transit/admin/login_request.php — الخطوة 1: هاتف المشرف → OTP
|
|
// POST: phone
|
|
|
|
require_once __DIR__ . '/../../core/bootstrap.php';
|
|
require_once __DIR__ . '/../functions.php';
|
|
|
|
// Rate limiting — حد صارم على طلبات OTP
|
|
$limiter = new RateLimiter($redis);
|
|
$limiter->enforce(RateLimiter::identifier(), 'api');
|
|
|
|
try { $transit_con = Database::get('transit'); }
|
|
catch (Exception $e) { jsonError('Transit service unavailable', 503); }
|
|
|
|
$rawPhone = filterRequest('phone');
|
|
if (!$rawPhone) jsonError('Phone is required');
|
|
$phone = normalizePhone($rawPhone);
|
|
|
|
if (transitIsOtpLocked($phone)) {
|
|
// نفس رسالة النجاح — لا نكشف أن الحساب مقفل
|
|
jsonSuccess(null, 'OTP sent successfully');
|
|
}
|
|
|
|
$phoneEnc = $encryptionHelper->encryptData($phone);
|
|
$st = $transit_con->prepare(
|
|
"SELECT a.id, o.contract_status
|
|
FROM transit_org_admins a
|
|
JOIN transit_orgs o ON o.id = a.org_id
|
|
WHERE a.phone = ? AND a.is_active = 1 LIMIT 1"
|
|
);
|
|
$st->execute([$phoneEnc]);
|
|
$admin = $st->fetch();
|
|
|
|
// لا نكشف إن كان الهاتف موجوداً أم لا — نفس الرد دائماً
|
|
if (!$admin || $admin['contract_status'] === 'terminated') {
|
|
jsonSuccess(null, 'OTP sent successfully');
|
|
}
|
|
|
|
transitSendAdminOtp($phone);
|
|
|
|
jsonSuccess(null, 'OTP sent successfully');
|