Files
Siro/backend/ride/firebase/getTokenParent.php
T
Hamza-AyedandClaude Opus 5 8d7e3118b5 Migrate remaining encrypted-column lookups to the blind index
Completes the set of queries that matched a freshly encrypted value against a
stored one, which only works while encryption is deterministic. Each keeps its
original comparison and adds an index comparison in the same WHERE, so nothing
changes today.

- passenger sign-in by email, service-staff sign-in, Firebase token lookup
- driver lookup by phone and by national number
- admin ride lookup and ride monitor (both tables)
- nabeh: driver status, user resolution, ride history, complaint submission

transit_org_admins lives in the transit database and has no index column, so
login there falls back to decrypting the small set of active admins and
comparing normalised numbers.

Schema: adds users.email_bidx/phone_bidx and driver.national_bidx with their
indexes.

Verified that every :*_bidx placeholder introduced is actually bound — an
unbound one is a fatal error at request time, not a silent miss.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 16:36:32 +03:00

48 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/../../connect.php';
$phone = filterRequest("phone");
// 🔐 تشفير رقم الهاتف قبل البحث (لأنه مشفّر في قاعدة البيانات)
$phoneEncrypted = $encryptionHelper->encryptData($phone);
global $blindIndex;
$phoneBidx = $blindIndex ? $blindIndex->index('passengers.phone', $phone) : null;
// 1️⃣ جلب passengerID بناءً على رقم الهاتف
$sql = "SELECT `id` FROM `passengers` WHERE `phone` = :phone OR (:phone_bidx IS NOT NULL AND `phone_bidx` = :phone_bidx)";
$stmt = $con->prepare($sql);
$stmt->bindParam(':phone', $phoneEncrypted);
$stmt->bindParam(':phone_bidx', $phoneBidx);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
if ($data) {
$passengerID = $data['id'];
} else {
jsonError("No passenger found for the given phone number");
exit;
}
// 2️⃣ جلب التوكنات المرتبطة بـ passengerID
$sql1 = "SELECT * FROM `tokens` WHERE `passengerID` = :passengerID";
$stmt = $con->prepare($sql1);
$stmt->bindParam(':passengerID', $passengerID);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($data) {
// فك تشفير التوكن فقط
foreach ($data as &$row) {
$row['token'] = $encryptionHelper->decryptData($row['token']);
// fingerPrint يبقى كما هو
}
echo json_encode([
'status' => 'success',
'count' => count($data),
'data' => $data
]);
} else {
jsonError("No tokens found for the passenger");
}
?>