Guest User

Untitled

a guest
Feb 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. require_once 'include/DB_Functions.php';
  3. $db = new DB_Functions();
  4.  
  5. // json response array
  6. $response = array("error" => FALSE);
  7.  
  8. if (isset($_POST['email']) && isset($_POST['password'])) {
  9.  
  10. // receiving the post params
  11. $email = $_POST['email'];
  12. $password = $_POST['password'];
  13.  
  14. // get the user by email and password
  15. $user = $db->getUserByEmailAndPassword($email, $password);
  16.  
  17. if ($user != false) {
  18. // use is found
  19. $response["error"] = FALSE;
  20. $response["uid"] = $user["unique_id"];
  21. $response["user"]["name"] = $user["name"];
  22. $response["user"]["email"] = $user["email"];
  23. $response["user"]["created_at"] = $user["created_at"];
  24. $response["user"]["updated_at"] = $user["updated_at"];
  25. echo json_encode($response);
  26. } else {
  27. // user is not found with the credentials
  28. $response["error"] = TRUE;
  29. $response["error_msg"] = "Login credentials are wrong. Please try again!";
  30. echo json_encode($response);
  31. }
  32. } else {
  33. // required post params is missing
  34. $response["error"] = TRUE;
  35. $response["error_msg"] = "Required parameters email or password is missing!";
  36. echo json_encode($response);
  37. }
  38. ?>
Add Comment
Please, Sign In to add comment