phpstan level 0 error free - fixes for kyu subpage - move mams into participo framework - remove legacy `lib/db.php` usage - add attributer admin function - add newsposter - fixing apiKey creation
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
require_once "bootstrap.php";
|
|
|
|
require_once "participoLib/participo.php";
|
|
require_once "participoLib/apiKey.php";
|
|
|
|
participo::initDb(
|
|
$CONFIG["cwsvJudo"]["db"]["host"],
|
|
$CONFIG["cwsvJudo"]["db"]["name"],
|
|
$CONFIG["cwsvJudo"]["db"]["user"],
|
|
$SECRETS["cwsvJudo"]["db"][$CONFIG["cwsvJudo"]["db"]["user"]],
|
|
$CONFIG["cwsvJudo"]["db"]["dbCharset"],
|
|
$CONFIG["cwsvJudo"]["db"]["outCharset"],
|
|
);
|
|
|
|
$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]);
|
|
}
|