wip: participo rest api users endpoint
This commit is contained in:
@@ -7,52 +7,61 @@ require_once 'local/cwsvJudo.php';
|
|||||||
|
|
||||||
require_once 'participoLib/participo.php';
|
require_once 'participoLib/participo.php';
|
||||||
|
|
||||||
|
$db = dbConnector::connect(
|
||||||
|
$cwsvJudoConfig['db']['host'],
|
||||||
|
$cwsvJudoConfig['db']['name'],
|
||||||
|
$cwsvJudoConfig['db']['user'],
|
||||||
|
$cwsvJudoConfig['db']['password']
|
||||||
|
);
|
||||||
|
|
||||||
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
|
function authorize(){
|
||||||
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
|
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
|
||||||
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
|
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
|
||||||
if($auth[0]="Basic"){
|
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
|
||||||
$db = dbConnector::connect(
|
if($auth[0]="Basic"){
|
||||||
$cwsvJudoConfig['db']['host'],
|
$allowKey = ApiKey::loadFromDb($auth[1]);
|
||||||
$cwsvJudoConfig['db']['name'],
|
}
|
||||||
$cwsvJudoConfig['db']['user'],
|
|
||||||
$cwsvJudoConfig['db']['password']
|
|
||||||
);
|
|
||||||
$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"
|
|
||||||
." `wkParticipo_Users`.* "
|
|
||||||
." FROM `wkParticipo_Users`"
|
|
||||||
." JOIN `vormundschaft`"
|
|
||||||
." ON `wkParticipo_Users`.`id` =`vormundschaft`.`userId`"
|
|
||||||
." JOIN `wkParticipo_user<=>userAttributes`"
|
|
||||||
." ON `wkParticipo_user<=>userAttributes`.`userId` = `vormundschaft`.`kidId`"
|
|
||||||
." WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4"
|
|
||||||
." ORDER BY `wkParticipo_Users`.`id` ASC;";
|
|
||||||
|
|
||||||
$wkSqlResponse = dbConnector::query($wkSqlQuery);
|
|
||||||
|
|
||||||
// Postprocessing
|
|
||||||
// - convert the comma separated list into an array
|
|
||||||
foreach( $wkSqlResponse as &$user){
|
|
||||||
$user['eMail'] = explode(",", $user['eMail']);
|
|
||||||
foreach( $user['eMail'] as &$email){
|
|
||||||
$email = trim($email);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get(){
|
||||||
|
$wkSqlQuery = "SELECT DISTINCT"
|
||||||
|
." `wkParticipo_Users`.* "
|
||||||
|
." FROM `wkParticipo_Users`"
|
||||||
|
." JOIN `vormundschaft`"
|
||||||
|
." ON `wkParticipo_Users`.`id` =`vormundschaft`.`userId`"
|
||||||
|
." JOIN `wkParticipo_user<=>userAttributes`"
|
||||||
|
." ON `wkParticipo_user<=>userAttributes`.`userId` = `vormundschaft`.`kidId`"
|
||||||
|
." WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4"
|
||||||
|
." ORDER BY `wkParticipo_Users`.`id` ASC;";
|
||||||
|
|
||||||
|
$wkSqlResponse = dbConnector::query($wkSqlQuery);
|
||||||
|
|
||||||
|
// Postprocessing
|
||||||
|
// - convert the comma separated list into an array
|
||||||
|
foreach( $wkSqlResponse as &$user){
|
||||||
|
$user['eMail'] = explode(",", $user['eMail']);
|
||||||
|
foreach( $user['eMail'] as &$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)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user