Update: 2026-06-24 16:27:39
This commit is contained in:
@@ -57,27 +57,36 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. Encrypt data to query
|
// 3. Encrypt data to query
|
||||||
$encryptedPhone = $encryptionHelper->encryptData($phone_number);
|
|
||||||
$encryptedToken = $encryptionHelper->encryptData($token_code);
|
|
||||||
|
|
||||||
// 4. Verify based on user type
|
// 4. Verify based on user type
|
||||||
try {
|
try {
|
||||||
if ($user_type === 'admin') {
|
if ($user_type === 'admin') {
|
||||||
$sql = "SELECT * FROM token_verification_admin
|
$sql = "SELECT * FROM token_verification_admin
|
||||||
WHERE phone_number = :phone AND token = :token
|
WHERE expiration_time >= NOW() AND verified = 0";
|
||||||
AND expiration_time >= NOW() AND verified = 0";
|
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
|
||||||
$stmt->bindParam(':token', $encryptedToken, PDO::PARAM_STR);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($stmt->rowCount() > 0) {
|
$matchedRow = null;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$decryptedPhone = $encryptionHelper->decryptData($row['phone_number']);
|
||||||
|
$decryptedToken = $encryptionHelper->decryptData($row['token']);
|
||||||
|
if ($decryptedPhone === $phone_number && $decryptedToken === $token_code) {
|
||||||
|
$matchedRow = $row;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matchedRow) {
|
||||||
$deviceNumber = filterRequest("device_number") ?? '';
|
$deviceNumber = filterRequest("device_number") ?? '';
|
||||||
// adminUser stores unencrypted phone
|
// adminUser stores unencrypted phone
|
||||||
$checkAdmin = $con->prepare("SELECT * FROM adminUser WHERE name = ?");
|
$checkAdmin = $con->prepare("SELECT * FROM adminUser WHERE name = ?");
|
||||||
$checkAdmin->execute([$phone_number]);
|
$checkAdmin->execute([$phone_number]);
|
||||||
$now = date("Y-m-d H:i:s");
|
$now = date("Y-m-d H:i:s");
|
||||||
|
|
||||||
|
// Mark token as verified
|
||||||
|
$updateToken = $con->prepare("UPDATE token_verification_admin SET verified = 1 WHERE phone_number = ? AND token = ?");
|
||||||
|
$updateToken->execute([$matchedRow['phone_number'], $matchedRow['token']]);
|
||||||
|
|
||||||
if ($checkAdmin->rowCount() > 0) {
|
if ($checkAdmin->rowCount() > 0) {
|
||||||
$update = $con->prepare("UPDATE adminUser SET device_number = ?, updated_at = ? WHERE name = ?");
|
$update = $con->prepare("UPDATE adminUser SET device_number = ?, updated_at = ? WHERE name = ?");
|
||||||
$update->execute([$deviceNumber, $now, $phone_number]);
|
$update->execute([$deviceNumber, $now, $phone_number]);
|
||||||
@@ -91,19 +100,26 @@ try {
|
|||||||
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
||||||
}
|
}
|
||||||
} elseif ($user_type === 'service') {
|
} elseif ($user_type === 'service') {
|
||||||
$sql = "SELECT `id` FROM `phone_verification_service`
|
$sql = "SELECT `id`, `phone_number`, `token_code` FROM `phone_verification_service`
|
||||||
WHERE `phone_number` = :phone AND `token_code` = :token
|
WHERE `expiration_time` > NOW() AND `is_verified` = 0";
|
||||||
AND `expiration_time` > NOW() AND `is_verified` = 0";
|
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
|
||||||
$stmt->bindParam(':token', $encryptedToken, PDO::PARAM_STR);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->fetch();
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result) {
|
$matchedRowId = null;
|
||||||
$sqlUpdate = "UPDATE `phone_verification_service` SET `is_verified` = 1 WHERE `phone_number` = :phone";
|
foreach ($rows as $row) {
|
||||||
|
$decryptedPhone = $encryptionHelper->decryptData($row['phone_number']);
|
||||||
|
$decryptedToken = $encryptionHelper->decryptData($row['token_code']);
|
||||||
|
if ($decryptedPhone === $phone_number && $decryptedToken === $token_code) {
|
||||||
|
$matchedRowId = $row['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matchedRowId) {
|
||||||
|
$sqlUpdate = "UPDATE `phone_verification_service` SET `is_verified` = 1 WHERE `id` = :id";
|
||||||
$stmtUpd = $con->prepare($sqlUpdate);
|
$stmtUpd = $con->prepare($sqlUpdate);
|
||||||
$stmtUpd->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
$stmtUpd->bindParam(':id', $matchedRowId, PDO::PARAM_INT);
|
||||||
$stmtUpd->execute();
|
$stmtUpd->execute();
|
||||||
jsonSuccess(null, "Your phone number has been verified.");
|
jsonSuccess(null, "Your phone number has been verified.");
|
||||||
} else {
|
} else {
|
||||||
@@ -111,47 +127,53 @@ try {
|
|||||||
}
|
}
|
||||||
} elseif ($user_type === 'driver') {
|
} elseif ($user_type === 'driver') {
|
||||||
if ($context === 'token_change') {
|
if ($context === 'token_change') {
|
||||||
$sql = "SELECT `id` FROM `token_verification_driver`
|
$sql = "SELECT `id`, `phone_number`, `token` FROM `token_verification_driver`
|
||||||
WHERE `phone_number` = :phone
|
WHERE `expiration_time` > NOW() AND `verified` = 0";
|
||||||
AND `token` = :token
|
|
||||||
AND `expiration_time` > NOW() AND `verified` = 0";
|
|
||||||
|
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
|
||||||
$stmt->bindParam(':token', $encryptedToken, PDO::PARAM_STR);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->fetch();
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result) {
|
$matchedRowId = null;
|
||||||
// Update driver verified status
|
foreach ($rows as $row) {
|
||||||
$sqlUpdate = "UPDATE `token_verification_driver` SET `verified` = 1 WHERE `phone_number` = :phone";
|
$decryptedPhone = $encryptionHelper->decryptData($row['phone_number']);
|
||||||
|
$decryptedToken = $encryptionHelper->decryptData($row['token']);
|
||||||
|
if ($decryptedPhone === $phone_number && $decryptedToken === $token_code) {
|
||||||
|
$matchedRowId = $row['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matchedRowId) {
|
||||||
|
$sqlUpdate = "UPDATE `token_verification_driver` SET `verified` = 1 WHERE `id` = :id";
|
||||||
$stmtUpd = $con->prepare($sqlUpdate);
|
$stmtUpd = $con->prepare($sqlUpdate);
|
||||||
$stmtUpd->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
$stmtUpd->bindParam(':id', $matchedRowId, PDO::PARAM_INT);
|
||||||
$stmtUpd->execute();
|
$stmtUpd->execute();
|
||||||
|
|
||||||
jsonSuccess(null, "Your phone number has been verified.");
|
jsonSuccess(null, "Your phone number has been verified.");
|
||||||
} else {
|
} else {
|
||||||
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT `id` FROM `phone_verification`
|
$sql = "SELECT `id`, `phone_number`, `token_code` FROM `phone_verification`
|
||||||
WHERE `phone_number` = :phone
|
WHERE `expiration_time` > NOW() AND `is_verified` = 0";
|
||||||
AND `token_code` = :token
|
|
||||||
AND `expiration_time` > NOW() AND `is_verified` = 0";
|
|
||||||
|
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
|
||||||
$stmt->bindParam(':token', $encryptedToken, PDO::PARAM_STR);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->fetch();
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result) {
|
$matchedRowId = null;
|
||||||
// Update driver is_verified status
|
foreach ($rows as $row) {
|
||||||
$sqlUpdate = "UPDATE `phone_verification` SET `is_verified` = 1 WHERE `phone_number` = :phone";
|
$decryptedPhone = $encryptionHelper->decryptData($row['phone_number']);
|
||||||
|
$decryptedToken = $encryptionHelper->decryptData($row['token_code']);
|
||||||
|
if ($decryptedPhone === $phone_number && $decryptedToken === $token_code) {
|
||||||
|
$matchedRowId = $row['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matchedRowId) {
|
||||||
|
$sqlUpdate = "UPDATE `phone_verification` SET `is_verified` = 1 WHERE `id` = :id";
|
||||||
$stmtUpd = $con->prepare($sqlUpdate);
|
$stmtUpd = $con->prepare($sqlUpdate);
|
||||||
$stmtUpd->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
$stmtUpd->bindParam(':id', $matchedRowId, PDO::PARAM_INT);
|
||||||
$stmtUpd->execute();
|
$stmtUpd->execute();
|
||||||
|
|
||||||
jsonSuccess(null, "Your phone number has been verified.");
|
jsonSuccess(null, "Your phone number has been verified.");
|
||||||
} else {
|
} else {
|
||||||
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
||||||
@@ -159,47 +181,53 @@ try {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($context === 'token_change') {
|
if ($context === 'token_change') {
|
||||||
$sql = "SELECT `id` FROM `token_verification`
|
$sql = "SELECT `id`, `phone_number`, `token` FROM `token_verification`
|
||||||
WHERE `phone_number` = :phone
|
WHERE `expiration_time` > NOW() AND `verified` = 0";
|
||||||
AND `token` = :token
|
|
||||||
AND `expiration_time` > NOW() AND `verified` = 0";
|
|
||||||
|
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
|
||||||
$stmt->bindParam(':token', $encryptedToken, PDO::PARAM_STR);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->fetch();
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result) {
|
$matchedRowId = null;
|
||||||
// Update passenger verified status
|
foreach ($rows as $row) {
|
||||||
$sqlUpdate = "UPDATE `token_verification` SET `verified` = 1 WHERE `phone_number` = :phone";
|
$decryptedPhone = $encryptionHelper->decryptData($row['phone_number']);
|
||||||
|
$decryptedToken = $encryptionHelper->decryptData($row['token']);
|
||||||
|
if ($decryptedPhone === $phone_number && $decryptedToken === $token_code) {
|
||||||
|
$matchedRowId = $row['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matchedRowId) {
|
||||||
|
$sqlUpdate = "UPDATE `token_verification` SET `verified` = 1 WHERE `id` = :id";
|
||||||
$stmtUpd = $con->prepare($sqlUpdate);
|
$stmtUpd = $con->prepare($sqlUpdate);
|
||||||
$stmtUpd->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
$stmtUpd->bindParam(':id', $matchedRowId, PDO::PARAM_INT);
|
||||||
$stmtUpd->execute();
|
$stmtUpd->execute();
|
||||||
|
|
||||||
jsonSuccess(null, "Your phone number has been verified.");
|
jsonSuccess(null, "Your phone number has been verified.");
|
||||||
} else {
|
} else {
|
||||||
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT `id` FROM `phone_verification_passenger`
|
$sql = "SELECT `id`, `phone_number`, `token` FROM `phone_verification_passenger`
|
||||||
WHERE `phone_number` = :phone
|
WHERE `expiration_time` > NOW() AND `verified` = 0";
|
||||||
AND `token` = :token
|
|
||||||
AND `expiration_time` > NOW() AND `verified` = 0";
|
|
||||||
|
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
|
||||||
$stmt->bindParam(':token', $encryptedToken, PDO::PARAM_STR);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->fetch();
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result) {
|
$matchedRowId = null;
|
||||||
// Update passenger verified status
|
foreach ($rows as $row) {
|
||||||
$sqlUpdate = "UPDATE `phone_verification_passenger` SET `verified` = 1 WHERE `phone_number` = :phone";
|
$decryptedPhone = $encryptionHelper->decryptData($row['phone_number']);
|
||||||
|
$decryptedToken = $encryptionHelper->decryptData($row['token']);
|
||||||
|
if ($decryptedPhone === $phone_number && $decryptedToken === $token_code) {
|
||||||
|
$matchedRowId = $row['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matchedRowId) {
|
||||||
|
$sqlUpdate = "UPDATE `phone_verification_passenger` SET `verified` = 1 WHERE `id` = :id";
|
||||||
$stmtUpd = $con->prepare($sqlUpdate);
|
$stmtUpd = $con->prepare($sqlUpdate);
|
||||||
$stmtUpd->bindParam(':phone', $encryptedPhone, PDO::PARAM_STR);
|
$stmtUpd->bindParam(':id', $matchedRowId, PDO::PARAM_INT);
|
||||||
$stmtUpd->execute();
|
$stmtUpd->execute();
|
||||||
|
|
||||||
jsonSuccess(null, "Your phone number has been verified.");
|
jsonSuccess(null, "Your phone number has been verified.");
|
||||||
} else {
|
} else {
|
||||||
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
jsonError("Your phone number could not be verified or the code is expired. Please try again.");
|
||||||
|
|||||||
Reference in New Issue
Block a user