ApiKeys fixed + tests

This commit is contained in:
2020-04-02 16:31:17 +02:00
parent cc334eb62d
commit 541b8563d5
6 changed files with 60 additions and 13 deletions

View File

@@ -28,9 +28,13 @@ class CreateApiKey extends Request {
$this->lastError = $sql->getLastError();
if ($this->success) {
$this->result["api_key"] = $apiKey;
$this->result["valid_until"] = $validUntil->getTimestamp();
$this->result["uid"] = $sql->getLastInsertId();
$this->result["api_key"] = array(
"api_key" => $apiKey,
"valid_until" => $validUntil->getTimestamp(),
"uid" => $sql->getLastInsertId(),
);
} else {
$this->result["api_key"] = null;
}
return $this->success;
}

View File

@@ -28,7 +28,14 @@ class GetApiKeys extends Request {
$this->lastError = $sql->getLastError();
if($this->success) {
$this->result["api_keys"] = $res;
$this->result["api_keys"] = array();
foreach($res as $row) {
$this->result["api_keys"][] = array(
"uid" => $row["uid"],
"api_key" => $row["api_key"],
"valid_until" => (new \DateTime($row["valid_until"]))->getTimestamp(),
);
}
}
return $this->success;

View File

@@ -18,7 +18,7 @@ class RefreshApiKey extends Request {
$id = $this->getParam("id");
$sql = $this->user->getSQL();
$res = $sql->select("COUNT(*)")
$res = $sql->select($sql->count())
->from("ApiKey")
->where(new Compare("uid", $id))
->where(new Compare("user_id", $this->user->getId()))
@@ -29,7 +29,7 @@ class RefreshApiKey extends Request {
$this->success = ($res !== FALSE);
$this->lastError = $sql->getLastError();
if($this->success && $res[0]["COUNT(*)"] === 0) {
if($this->success && $res[0]["count"] === 0) {
$this->success = false;
$this->lastError = "This API-Key does not exist.";
}

View File

@@ -18,7 +18,7 @@ class RevokeApiKey extends Request {
$id = $this->getParam("id");
$sql = $this->user->getSQL();
$res = $sql->select("COUNT(*)")
$res = $sql->select($sql->count())
->from("ApiKey")
->where(new Compare("uid", $id))
->where(new Compare("user_id", $this->user->getId()))
@@ -29,7 +29,7 @@ class RevokeApiKey extends Request {
$this->success = ($res !== FALSE);
$this->lastError = $sql->getLastError();
if($this->success && $res[0]["COUNT(*)"] === 0) {
if($this->success && $res[0]["count"] === 0) {
$this->success = false;
$this->lastError = "This API-Key does not exist.";
}