Files
cwsvJudo/homepage/participo/api.apiKeys.add.php
2022-11-19 12:57:49 +01:00

39 lines
935 B
PHP

<?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]));
}