add apiKey management

This commit is contained in:
marko
2022-11-19 12:57:49 +01:00
parent b1de004603
commit 7a531a1d4c
10 changed files with 466 additions and 236 deletions

View File

@@ -0,0 +1,38 @@
<?php
require_once 'config/participo.php';
require_once './local/cwsvJudo.php';
require_once 'participoLib/apiKey.php';
dbConnector::connect(
$cwsvJudoConfig['db']['host'],
$cwsvJudoConfig['db']['name'],
$cwsvJudoConfig['db']['user'],
$cwsvJudoConfig['db']['password']
);
$jsonPost = file_get_contents('php://input');
$call = json_decode($jsonPost, $associative = true);
if ($call) {
$allowKey = ApiKey::loadFromDb($call['apiKey']);
if (!$allowKey) {
die(json_encode(['success' => false]));
}
if (!$allowKey->isValidFor('apiKeys.create')) {
die(json_encode(['success' => false]));
}
$newKey = ApiKey::create();
$newLoginApiKey = new ApiKey(null, $call['userId'], $newKey, 'login', $call['endDate']);
$newLoginApiKey->addToDb();
$insertedApiKey = ApiKey::loadFromDb($newKey);
if (!$insertedApiKey) {
die(json_encode(['success' => false]));
}
echo(json_encode(['success' => true, 'apiKey' => $newKey]));
}