Upload
This commit is contained in:
parent
e55dc42068
commit
576b1634a6
@ -29,7 +29,7 @@ if (!is_null($token)) {
|
|||||||
$stmt->close();
|
$stmt->close();
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo '{"success":"' . $response['success'] . '", "isAuthenticated":' . $response['success'] . ', "token":"'. $response['token'] .'", "expires":' . $response['expires'] . ', "message":"' . $response['message'] . '"' . '}';
|
echo '{"success":"' . $response['success'] . '", "isAuthenticated":' . $response['success'] . ', "token":"'. $response['token'] .'", "expires":' . $response['expires'] . ', "message":"' . $response['message'] . '"}';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,8 @@ if ($result->num_rows > 0) {
|
|||||||
$stmt->close();
|
$stmt->close();
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
|
||||||
|
|
||||||
// Return JSON response
|
// Return JSON response
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo '{"success":"' . $response['success'] . '", "isAuthenticated":' . $response['success'] . ', "token":"'. $response['token'] .'", "expires":' . $response['expires'] . ', "message":"' . $response['message'] . '"' . '}';
|
echo '{"success":"' . $response['success'] . '", "isAuthenticated":' . $response['success'] . ', "token":"'. $response['token'] .'", "expires":' . $response['expires'] . ', "message":"' . $response['message'] . '"}';
|
||||||
|
|
||||||
|
34
api/tunnel.php
Normal file
34
api/tunnel.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/db_config.php');
|
||||||
|
|
||||||
|
$token = get_bearer_token();
|
||||||
|
if (is_null($token)) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
http_response_code(412);
|
||||||
|
echo '{"error":true,"message":"No token provided"}';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = $mysqli->real_escape_string($token);
|
||||||
|
|
||||||
|
$stmt = $mysqli->prepare("SELECT id FROM users WHERE token = ?");
|
||||||
|
$stmt->bind_param('s', $token);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
$row = $result->fetch_assoc();
|
||||||
|
if (!is_null($row)) {
|
||||||
|
$user_id = $row['id'];
|
||||||
|
$stmt->close();
|
||||||
|
$stmt = $mysqli->prepare("SELECT * FROM tunnels WHERE user = ?");
|
||||||
|
$stmt->bind_param('i', $user_id);
|
||||||
|
} else {
|
||||||
|
// return No user found
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
http_response_code(403);
|
||||||
|
echo '{"error":true,"message":"Unauthorized"}';
|
||||||
|
$stmt->close();
|
||||||
|
$mysqli->close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
@ -33,4 +33,5 @@ function get_bearer_token(): ?string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
testing/api/auth.php
Normal file
3
testing/api/auth.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo '{"success":true,"isAuthenticated":true,"token":"1a2b3c4d5e6f7g8h9i0j","expires":2524608000000,"message":"success"}';
|
3
testing/api/user-info.php
Normal file
3
testing/api/user-info.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo '{"success":true, "message":"success", "username":"test account", "email":"test@test.com"}';
|
Loading…
Reference in New Issue
Block a user