47 lines
1.8 KiB
PHP
Executable File
47 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
// استقبال المتغيرات
|
|
$token = filterRequest("token"); // نص عادي ➜ سيتم تشفيره
|
|
$passengerID = filterRequest("passengerID"); // ID عادي
|
|
$fingerPrint = filterRequest("fingerPrint"); // مشفّر مسبقًا من Flutter ➜ لا يتم تشفيره هنا
|
|
|
|
// تشفير التوكن فقط
|
|
$tokenEncrypted = $encryptionHelper->encryptData($token);
|
|
|
|
// التحقق مما إذا كان السجل موجودًا
|
|
$sqlCheck = "SELECT * FROM `tokens` WHERE `passengerID` = :passengerID";
|
|
$stmtCheck = $con->prepare($sqlCheck);
|
|
$stmtCheck->bindParam(':passengerID', $passengerID);
|
|
$stmtCheck->execute();
|
|
|
|
$result = $stmtCheck->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($result) {
|
|
// تحديث السجل الموجود
|
|
$sqlUpdate = "UPDATE `tokens` SET `token` = :token, `fingerPrint` = :fingerPrint WHERE `passengerID` = :passengerID";
|
|
$stmtUpdate = $con->prepare($sqlUpdate);
|
|
$stmtUpdate->bindParam(':token', $tokenEncrypted);
|
|
$stmtUpdate->bindParam(':fingerPrint', $fingerPrint); // بدون تشفير إضافي
|
|
$stmtUpdate->bindParam(':passengerID', $passengerID);
|
|
$stmtUpdate->execute();
|
|
|
|
jsonSuccess(null, "Token updated successfully");
|
|
|
|
} else {
|
|
// إدخال سجل جديد
|
|
$sqlInsert = "INSERT INTO `tokens` (`token`, `passengerID`, `fingerPrint`) VALUES (:token, :passengerID, :fingerPrint)";
|
|
$stmtInsert = $con->prepare($sqlInsert);
|
|
$stmtInsert->bindParam(':token', $tokenEncrypted);
|
|
$stmtInsert->bindParam(':passengerID', $passengerID);
|
|
$stmtInsert->bindParam(':fingerPrint', $fingerPrint); // بدون تشفير إضافي
|
|
$stmtInsert->execute();
|
|
|
|
if ($stmtInsert->rowCount() > 0) {
|
|
jsonSuccess(null, "Token inserted successfully");
|
|
} else {
|
|
jsonError("Failed to insert token");
|
|
}
|
|
}
|
|
?>
|