develop version for new api concept
This commit is contained in:
40
homepage/participo/api/users.php
Normal file
40
homepage/participo/api/users.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/'. PATH_SEPARATOR. '..');
|
||||
|
||||
require_once 'config/participo.php';
|
||||
require_once 'local/cwsvJudo.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(
|
||||
$cwsvJudoConfig['db']['host'],
|
||||
$cwsvJudoConfig['db']['name'],
|
||||
$cwsvJudoConfig['db']['user'],
|
||||
$cwsvJudoConfig['db']['password']
|
||||
);
|
||||
$allowKey = ApiKey::loadFromDb($auth[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$allowKey || !$allowKey->isValidFor('api')) {
|
||||
die(json_encode(['success' => false]));
|
||||
}
|
||||
|
||||
$wkSqlQuery = 'SELECT * FROM `wettkampfkalender` WHERE `Datum` >= CURDATE();';
|
||||
$wkSqlResponse = dbConnector::query($wkSqlQuery);
|
||||
|
||||
header('Access-Control-Allow-Headers: *');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
echo(
|
||||
json_encode($wkSqlResponse)
|
||||
// json_encode(getallheaders())
|
||||
// json_encode($_SERVER)
|
||||
);
|
||||
33
homepage/participo/testApi.py
Normal file
33
homepage/participo/testApi.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from http import client
|
||||
import logging
|
||||
import json
|
||||
import yaml
|
||||
|
||||
host="cwsvjudo.bplaced.net"
|
||||
|
||||
with open("testApi.config.yaml", "r") as f:
|
||||
config = yaml.load(f)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
connection = client.HTTPConnection(host=host, port=80, timeout=1)
|
||||
connection.request(
|
||||
method="GET",
|
||||
url="/participo/api/users",
|
||||
headers={
|
||||
"Authorization": f"Basic {config['apiKey']}"
|
||||
}
|
||||
)
|
||||
response = connection.getresponse()
|
||||
|
||||
print("Status: {} and reason: {}".format(response.status, response.reason))
|
||||
|
||||
body = response.read()
|
||||
try:
|
||||
print(json.dumps(json.loads(body),indent=2))
|
||||
except:
|
||||
print(f"failed to parse to json")
|
||||
print(body
|
||||
)
|
||||
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user