Advertisement
Guest User

Untitled

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