Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. $entityBody = file_get_contents('php://input');
  2. $body = json_decode($entityBody,true);
  3. foreach ($body as $value)
  4. {
  5. $username = $value['username'];
  6. $oldPassword = $value['oldPassword'];
  7. $newPassword = $value['newPassword'];
  8. }
  9.  
  10. $con = new MongoDBClient;
  11. if($con){
  12. $db = $con->users;
  13. // Select Collection
  14. $collection = $db->user;
  15.  
  16. $filter = array(['Username' => $username,
  17. 'Password' => $oldPassword
  18. ]);
  19.  
  20. $qry = new MongoDBDriverQuery($filter);
  21.  
  22. $rows = $collection->findOne($qry);
  23.  
  24. if($rows['Username']== $username && $rows['Password'] == $oldPassword)
  25. {
  26. $criteria = ['Username' => $rows['Username']];
  27. $newData = ['$set' => ['Password' => $newPassword]];
  28.  
  29. $collection -> update($criteria,$newData);
  30. $changed = true;
  31.  
  32. echo json_encode(array('status'=> '1','isChanged' => $changed));
  33. }
  34. else{
  35.  
  36. $changed = false;
  37. echo json_encode(array('status'=> '2','isChanged' => $changed));
  38. }
  39. }
  40. else
  41. {
  42. die("Mongo DB not connected!");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement