-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditProfile.php
53 lines (41 loc) · 1.47 KB
/
editProfile.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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) {
$fullName = $_POST['fullName'];
$phone = $_POST['phone'];
$age = $_POST['age'];
$dob = $_POST['dob'];
$address = $_POST['address'];
$updatedData = array(
"userId" => $userId,
"fullName" => $fullName,
"phone" => $phone,
"age" => $age,
"dob" => $dob,
"address" => $address
);
$filter = ["userId" => $userId];
$update = [
'$set' => $updatedData,
];
$result = $usersCollection->updateOne($filter, $update);
if ($result->getModifiedCount() > 0) {
echo json_encode(["status" => "true", "message" => "Data edited"]);
} else {
echo json_encode(["status" => "false", "message" => "No matching document found for update"]);
}
} else {
echo json_encode(["status" => "false", "message" => "User not found"]);
}
} else {
echo json_encode(["status" => "false", "message" => "Authorization header is missing"]);
}
?>