-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetchDetails.php
38 lines (32 loc) · 1.09 KB
/
fetchDetails.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once 'redis_conn.php';
$mongodbConnection = new MongoDB\Client('mongodb://localhost:27017');
$myDatabase = $mongodbConnection->UserInfo;
$usersCollection = $myDatabase->users;
$headers = apache_request_headers();
if (isset($headers['Authorization'])) {
$token = str_replace('Bearer ', '', $headers['Authorization']);
$userId = $redis->get($token);
if ($userId !== null) {
$mongodata=array(
"userId"=>$userId,
);
$fetch = $usersCollection->findOne($mongodata);
echo json_encode([
"status" => "true",
"userId" => $userId,
"fullName" => $fetch['fullName'],
"phone" => $fetch['phone'],
"age" => $fetch['age'],
"dob" => $fetch['dob'],
"address" => $fetch['address']
]);
} else {
echo json_encode(["status" => "false", "message" => "User not found in the database"]);
}
}
else {
echo json_encode(["status" => "false", "message" => "Authorization header is missing"]);
}
?>