Database abstraction
This commit is contained in:
@@ -17,13 +17,20 @@ class CreateApiKey extends Request {
|
||||
}
|
||||
|
||||
$apiKey = generateRandomString(64);
|
||||
$query = "INSERT INTO ApiKey (user_id, api_key, valid_until) VALUES (?,?,(SELECT DATE_ADD(now(), INTERVAL 30 DAY)))";
|
||||
$request = new ExecuteStatement($this->user);
|
||||
$this->success = $request->execute(array("query" => $query, $this->user->getId(), $apiKey));
|
||||
$this->lastError = $request->getLastError();
|
||||
$this->result["api_key"] = $apiKey;
|
||||
$this->result["valid_until"] = "TODO";
|
||||
$this->result["uid"] = $this->user->getSQL()->getLastInsertId();
|
||||
$sql = $this->user->getSQL();
|
||||
$validUntil = (new \DateTime())->modify("+30 DAY");
|
||||
|
||||
$this->success = $sql->insert("ApiKey", array("user_id", "api_key", "valid_until"))
|
||||
->addRow($this->user->getId(), $apiKey, $validUntil)
|
||||
->execute();
|
||||
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$this->result["api_key"] = $apiKey;
|
||||
$this->result["valid_until"] = $validUntil->getTimestamp();
|
||||
$this->result["uid"] = $sql->getLastInsertId();
|
||||
}
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user