Advertisement
Guest User

Untitled

a guest
May 17th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2. //having trouble with this
  3. if (isset($_POST['tag']) && $_POST['tag'] != '') {
  4. $tag = $_POST['tag'];
  5.  
  6.  
  7. require_once 'include/DB_Functions.php';
  8. $db = new DB_Functions();
  9.  
  10. $response = array("tag" => $tag, "success" => 0, "error" => 0);
  11.  
  12. if ($tag == 'login') {
  13.  
  14. $email = $_POST['email'];
  15. $password = $_POST['password'];
  16.  
  17. $user = $db->getUserByEmailAndPassword($email, $password);
  18. if ($user != false) {
  19.  
  20. $response["success"] = 1;
  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. $response["error"] = 1;
  29. $response["error_msg"] = "Incorrect email or password!";
  30. echo json_encode($response);
  31. }
  32. } else if ($tag == 'register') {
  33.  
  34. $name = $_POST['name'];
  35. $email = $_POST['email'];
  36. $password = $_POST['password'];
  37.  
  38. if ($db->isUserExisted($email)) {
  39.  
  40. $response["error"] = 2;
  41. $response["error_msg"] = "User already existed";
  42. echo json_encode($response);
  43. } else {
  44. // store user
  45. $user = $db->storeUser($name, $email, $password);
  46. if ($user) {
  47. // user stored successfully
  48. $response["success"] = 1;
  49. $response["uid"] = $user["unique_id"];
  50. $response["user"]["name"] = $user["name"];
  51. $response["user"]["email"] = $user["email"];
  52. $response["user"]["created_at"] = $user["created_at"];
  53. $response["user"]["updated_at"] = $user["updated_at"];
  54. echo json_encode($response);
  55. }
  56. }
  57. } else {
  58. echo "Invalid Request";
  59. }
  60. } else {
  61. echo "Access Denied";
  62. //where the error is coming from
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement