add apiKey management
This commit is contained in:
38
homepage/participo/api.apiKeys.add.php
Normal file
38
homepage/participo/api.apiKeys.add.php
Normal 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]));
|
||||
}
|
||||
Reference in New Issue
Block a user