No Description

member.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. header('Content-type: application/json');
  3. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  4. # Gets json from POST
  5. $json = json_decode(file_get_contents('php://input'), true);
  6. # Input validation for username y password
  7. $token = $json["token"];
  8. if(strlen($token) == 0){
  9. http_response_code(400);
  10. echo json_encode(array("error" => "Ningun token."));
  11. exit();
  12. }
  13. include 'db.php';
  14. $sql = "SELECT token FROM Token WHERE token = \"".$token."\";";
  15. $result = $conn->query($sql);
  16. if($result === FALSE){
  17. http_response_code(500);
  18. echo json_encode(array("error" => "Error de base de datos 1."));
  19. $conn->close();
  20. exit();
  21. }
  22. if($result->num_rows == 0){
  23. http_response_code(401);
  24. echo json_encode(array("error" => "Token invalido."));
  25. $conn->close();
  26. exit();
  27. }
  28. $sql = "SELECT correo, nombre, organizacion, puesto, urbanizacion, calle, pueblo,
  29. cpostal, telefono, membresia, vigencia, horasTrabajadas FROM Token NATURAL JOIN Miembro NATURAL JOIN
  30. Login WHERE token = '".$token."'";
  31. $result = $conn->query($sql);
  32. if($result === FALSE){
  33. http_response_code(500);
  34. echo json_encode(array("error" => "Error de base de datos 2."));
  35. $conn->close();
  36. exit();
  37. } else if ($result->num_rows == 0) {
  38. http_response_code(500);
  39. echo json_encode(array("error" => "Error de base de datos 3."));
  40. $conn->close();
  41. exit();
  42. }
  43. $result = $result->fetch_assoc();
  44. http_response_code(200);
  45. echo json_encode($result);
  46. } else {
  47. header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
  48. exit();
  49. }
  50. ?>