first commit
This commit is contained in:
45
backend/ride/firebase/getTokenParent.php
Normal file
45
backend/ride/firebase/getTokenParent.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$phone = filterRequest("phone");
|
||||
|
||||
// 🔐 تشفير رقم الهاتف قبل البحث (لأنه مشفّر في قاعدة البيانات)
|
||||
$phoneEncrypted = $encryptionHelper->encryptData($phone);
|
||||
|
||||
// 1️⃣ جلب passengerID بناءً على رقم الهاتف
|
||||
$sql = "SELECT `id` FROM `passengers` WHERE `phone` = :phone";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':phone', $phoneEncrypted);
|
||||
$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");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user