Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// transit/driver/activate.php — السائق يفعّل حسابه (بدون JWT — قبل الدخول)
|
||||
// POST: invite_token, phone, otp
|
||||
|
||||
require_once __DIR__ . '/../../core/bootstrap.php';
|
||||
require_once __DIR__ . '/../functions.php';
|
||||
require_once __DIR__ . '/../../core/Services/OtpService.php';
|
||||
|
||||
try { $transit_con = Database::get('transit'); }
|
||||
catch (Exception $e) { jsonError('Transit service unavailable', 503); }
|
||||
|
||||
requireTransitFields(['invite_token','phone','otp']);
|
||||
$inviteToken = filterRequest('invite_token');
|
||||
$phone = normalizePhone(filterRequest('phone'));
|
||||
$otp = preg_replace('/\D/', '', filterRequest('otp'));
|
||||
|
||||
if (!transitVerifyAdminOtp($phone, $otp)) jsonError('Invalid or expired OTP', 401);
|
||||
|
||||
$phoneEnc = $encryptionHelper->encryptData($phone);
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT id, org_id, name, status FROM transit_drivers
|
||||
WHERE invite_token=? AND phone=? LIMIT 1"
|
||||
);
|
||||
$st->execute([$inviteToken, $phoneEnc]);
|
||||
$driver = $st->fetch();
|
||||
|
||||
if (!$driver) jsonError('Invalid invite token or phone mismatch', 404);
|
||||
if ($driver['status'] === 'active') jsonError('Driver already activated', 409);
|
||||
if ($driver['status'] === 'suspended') jsonError('Account suspended', 403);
|
||||
|
||||
$transit_con->prepare(
|
||||
"UPDATE transit_drivers SET status='active', activated_at=NOW(), invite_token=NULL WHERE id=?"
|
||||
)->execute([$driver['id']]);
|
||||
|
||||
jsonSuccess([
|
||||
'driver_id' => (int)$driver['id'],
|
||||
'org_id' => (int)$driver['org_id'],
|
||||
'name' => $driver['name'],
|
||||
'mode' => 'bus',
|
||||
], 'Driver activated. Welcome to مواصلاتي!');
|
||||
Reference in New Issue
Block a user