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,27 +7,30 @@ require_once 'local/cwsvJudo.php';
require_once 'participoLib/participo.php'; require_once 'participoLib/participo.php';
$db = dbConnector::connect(
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if($auth[0]="Basic"){
$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]);
} }
} }
} }
if (!$allowKey || !$allowKey->isValidFor('api')) { if (!$allowKey || !$allowKey->isValidFor('api')) {
die(json_encode(['success' => false])); die(json_encode(['success' => false]));
}
} }
$wkSqlQuery = "SELECT DISTINCT" function get(){
$wkSqlQuery = "SELECT DISTINCT"
." `wkParticipo_Users`.* " ." `wkParticipo_Users`.* "
." FROM `wkParticipo_Users`" ." FROM `wkParticipo_Users`"
." JOIN `vormundschaft`" ." JOIN `vormundschaft`"
@@ -37,22 +40,28 @@ $wkSqlQuery = "SELECT DISTINCT"
." WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4" ." WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4"
." ORDER BY `wkParticipo_Users`.`id` ASC;"; ." ORDER BY `wkParticipo_Users`.`id` ASC;";
$wkSqlResponse = dbConnector::query($wkSqlQuery); $wkSqlResponse = dbConnector::query($wkSqlQuery);
// Postprocessing // Postprocessing
// - convert the comma separated list into an array // - convert the comma separated list into an array
foreach( $wkSqlResponse as &$user){ foreach( $wkSqlResponse as &$user){
$user['eMail'] = explode(",", $user['eMail']); $user['eMail'] = explode(",", $user['eMail']);
foreach( $user['eMail'] as &$email){ foreach( $user['eMail'] as &$email){
$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)
); );