wip: participo rest api users endpoint

This commit is contained in:
marko
2023-12-25 11:13:26 +01:00
parent 38cc02120c
commit 49978a48df

View File

@@ -7,17 +7,18 @@ require_once 'local/cwsvJudo.php';
require_once 'participoLib/participo.php'; require_once 'participoLib/participo.php';
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if($auth[0]="Basic"){
$db = dbConnector::connect( $db = dbConnector::connect(
$cwsvJudoConfig['db']['host'], $cwsvJudoConfig['db']['host'],
$cwsvJudoConfig['db']['name'], $cwsvJudoConfig['db']['name'],
$cwsvJudoConfig['db']['user'], $cwsvJudoConfig['db']['user'],
$cwsvJudoConfig['db']['password'] $cwsvJudoConfig['db']['password']
); );
function authorize(){
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if($auth[0]="Basic"){
$allowKey = ApiKey::loadFromDb($auth[1]); $allowKey = ApiKey::loadFromDb($auth[1]);
} }
} }
@@ -26,7 +27,9 @@ if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
if (!$allowKey || !$allowKey->isValidFor('api')) { if (!$allowKey || !$allowKey->isValidFor('api')) {
die(json_encode(['success' => false])); die(json_encode(['success' => false]));
} }
}
function get(){
$wkSqlQuery = "SELECT DISTINCT" $wkSqlQuery = "SELECT DISTINCT"
." `wkParticipo_Users`.* " ." `wkParticipo_Users`.* "
." FROM `wkParticipo_Users`" ." FROM `wkParticipo_Users`"
@@ -47,12 +50,18 @@ foreach( $wkSqlResponse as &$user){
$email = trim($email); $email = trim($email);
} }
} }
return $wkSqlResponse;
}
authorize();
$wkSqlResponse = get();
// Sending Response // Sending Response
// - setting header // - setting header
header('Content-Type: application/json'); header('Content-Type: application/json');
// - sending body payload // - sending body payload
echo( // @todo die() seems to be more a error handling function. But echo+exit doesn't seem to close the connection (?). What leads to pythons requests.get() always wait for the complete timeout.
die(
json_encode($wkSqlResponse) json_encode($wkSqlResponse)
); );