Guest User

Untitled

a guest
Sep 5th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2.  
  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['name']) && isset($_POST['email']) && isset($_POST['password'])) {
  10.  
  11. // receiving the post params
  12. $name = $_POST['name'];
  13. $email = $_POST['email'];
  14. $password = $_POST['password'];
  15.  
  16. // check if user is already existed with the same email
  17. if ($db->isUserExisted($email)) {
  18. // user already existed
  19. $response["error"] = TRUE;
  20. $response["error_msg"] = "User already existed with " . $email;
  21. echo json_encode($response);
  22. } else {
  23. // create a new user
  24. $user = $db->storeUser($name, $email, $password);
  25. if ($user) {
  26. // user stored successfully
  27. $response["error"] = FALSE;
  28. $response["uid"] = $user["unique_id"];
  29. $response["user"]["name"] = $user["name"];
  30. $response["user"]["email"] = $user["email"];
  31. $response["user"]["created_at"] = $user["created_at"];
  32. $response["user"]["updated_at"] = $user["updated_at"];
  33. echo json_encode($response);
  34. } else {
  35. // user failed to store
  36. $response["error"] = TRUE;
  37. $response["error_msg"] = "Unknown error occurred in registration!";
  38. echo json_encode($response);
  39. }
  40. }
  41. } else {
  42. $response["error"] = TRUE;
  43. $response["error_msg"] = "Required parameters (name, email or password) is missing!";
  44. echo json_encode($response);
  45. }
  46. ?>
Add Comment
Please, Sign In to add comment