1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- header('Content-type: application/json');
-
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- # Gets json from POST
- $json = json_decode(file_get_contents('php://input'), true);
-
- # Input validation for username y password
- $token = $json["token"];
- if(strlen($token) == 0){
- http_response_code(400);
- echo json_encode(array("error" => "Ningun token."));
-
- exit();
- }
-
-
- include 'db.php';
-
- $sql = "SELECT token FROM Token WHERE token = \"".$token."\";";
- $result = $conn->query($sql);
-
- if($result === FALSE){
- http_response_code(500);
- echo json_encode(array("error" => "Error de base de datos 1."));
-
- $conn->close();
- exit();
- }
-
- if($result->num_rows == 0){
- http_response_code(401);
- echo json_encode(array("error" => "Token invalido."));
-
- $conn->close();
- exit();
- }
-
-
- $sql = "SELECT correo, nombre, organizacion, puesto, urbanizacion, calle, pueblo,
- cpostal, telefono, membresia, vigencia, horasTrabajadas FROM Token NATURAL JOIN Miembro NATURAL JOIN
- Login WHERE token = '".$token."'";
-
- $result = $conn->query($sql);
- if($result === FALSE){
- http_response_code(500);
- echo json_encode(array("error" => "Error de base de datos 2."));
-
- $conn->close();
- exit();
- } else if ($result->num_rows == 0) {
- http_response_code(500);
- echo json_encode(array("error" => "Error de base de datos 3."));
-
- $conn->close();
- exit();
- }
-
- $result = $result->fetch_assoc();
-
- http_response_code(200);
- echo json_encode($result);
-
- } else {
- header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
- exit();
- }
- ?>
|