small changes
This commit is contained in:
@@ -16,6 +16,7 @@ namespace Core\API\ApiKey {
|
||||
|
||||
use Core\API\ApiKeyAPI;
|
||||
use Core\API\Parameter\Parameter;
|
||||
use Core\API\Traits\Pagination;
|
||||
use Core\Driver\SQL\Condition\Compare;
|
||||
use Core\Driver\SQL\Condition\CondAnd;
|
||||
use Core\Driver\SQL\Query\Insert;
|
||||
@@ -32,17 +33,16 @@ namespace Core\API\ApiKey {
|
||||
|
||||
public function _execute(): bool {
|
||||
$sql = $this->context->getSQL();
|
||||
$currentUser = $this->context->getUser();
|
||||
|
||||
$apiKey = new ApiKey();
|
||||
$apiKey->apiKey = generateRandomString(64);
|
||||
$apiKey->validUntil = (new \DateTime())->modify("+30 DAY");
|
||||
$apiKey->user = $this->context->getUser();
|
||||
|
||||
$apiKey = ApiKey::create($currentUser);
|
||||
$this->success = $apiKey->save($sql);
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$this->result["api_key"] = $apiKey->jsonSerialize();
|
||||
$this->result["apiKey"] = $apiKey->jsonSerialize(
|
||||
["id", "validUntil", "token", "active"]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
@@ -55,10 +55,13 @@ namespace Core\API\ApiKey {
|
||||
|
||||
class Fetch extends ApiKeyAPI {
|
||||
|
||||
use Pagination;
|
||||
|
||||
public function __construct(Context $context, $externalCall = false) {
|
||||
parent::__construct($context, $externalCall, array(
|
||||
"showActiveOnly" => new Parameter("showActiveOnly", Parameter::TYPE_BOOLEAN, true, true)
|
||||
));
|
||||
$params = $this->getPaginationParameters(["token", "validUntil", "active"]);
|
||||
$params["showActiveOnly"] = new Parameter("showActiveOnly", Parameter::TYPE_BOOLEAN, true, true);
|
||||
|
||||
parent::__construct($context, $externalCall, $params);
|
||||
$this->loginRequired = true;
|
||||
}
|
||||
|
||||
@@ -74,14 +77,18 @@ namespace Core\API\ApiKey {
|
||||
);
|
||||
}
|
||||
|
||||
$apiKeys = ApiKey::findAll($sql, $condition);
|
||||
$this->success = ($apiKeys !== FALSE);
|
||||
if (!$this->initPagination($sql, ApiKey::class, $condition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$apiKeys = $this->createPaginationQuery($sql)->execute();
|
||||
$this->success = ($apiKeys !== FALSE && $apiKeys !== null);
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$this->result["api_keys"] = array();
|
||||
$this->result["apiKeys"] = [];
|
||||
foreach($apiKeys as $apiKey) {
|
||||
$this->result["api_keys"][$apiKey->getId()] = $apiKey->jsonSerialize();
|
||||
$this->result["apiKeys"][] = $apiKey->jsonSerialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Core\API {
|
||||
$settings = $req->getResult()["settings"];
|
||||
|
||||
if (!isset($settings["mail_enabled"]) || $settings["mail_enabled"] !== "1") {
|
||||
$this->createError("Mail is not configured yet.");
|
||||
$this->createError("Mailing is not configured on this server yet.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -252,13 +252,18 @@ namespace Core\API\TFA {
|
||||
// $domain = "localhost";
|
||||
|
||||
if (!$clientDataJSON || !$attestationObjectRaw) {
|
||||
$challenge = null;
|
||||
if ($twoFactorToken) {
|
||||
if (!($twoFactorToken instanceof KeyBasedTwoFactorToken) || $twoFactorToken->isConfirmed()) {
|
||||
if ($twoFactorToken->isConfirmed()) {
|
||||
return $this->createError("You already added a two factor token");
|
||||
} else {
|
||||
} else if ($twoFactorToken instanceof KeyBasedTwoFactorToken) {
|
||||
$challenge = $twoFactorToken->getChallenge();
|
||||
} else {
|
||||
$twoFactorToken->delete($sql);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if ($challenge === null) {
|
||||
$twoFactorToken = KeyBasedTwoFactorToken::create();
|
||||
$challenge = $twoFactorToken->getChallenge();
|
||||
$this->success = ($twoFactorToken->save($sql) !== false);
|
||||
@@ -307,6 +312,10 @@ namespace Core\API\TFA {
|
||||
|
||||
$this->success = $twoFactorToken->confirmKeyBased($sql, base64_encode($authData->getCredentialID()), $publicKey) !== false;
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$this->result["twoFactorToken"] = $twoFactorToken->jsonSerialize();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
|
||||
@@ -1223,6 +1223,8 @@ namespace Core\API\User {
|
||||
$gpgKey = $currentUser->getGPG();
|
||||
if ($gpgKey) {
|
||||
return $this->createError("You already added a GPG key to your account.");
|
||||
} else if (!$currentUser->getEmail()) {
|
||||
return $this->createError("You do not have an e-mail address");
|
||||
}
|
||||
|
||||
// fix key first, enforce a newline after
|
||||
@@ -1280,7 +1282,7 @@ namespace Core\API\User {
|
||||
if ($this->success) {
|
||||
$currentUser->gpgKey = $gpgKey;
|
||||
if ($currentUser->save($sql, ["gpgKey"])) {
|
||||
$this->result["gpg"] = $gpgKey->jsonSerialize();
|
||||
$this->result["gpgKey"] = $gpgKey->jsonSerialize();
|
||||
} else {
|
||||
return $this->createError("Error updating user details: " . $sql->getLastError());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user