small changes
This commit is contained in:
@@ -9,19 +9,23 @@ use Core\Objects\DatabaseEntity\Controller\DatabaseEntity;
|
||||
class ApiKey extends DatabaseEntity {
|
||||
|
||||
private bool $active;
|
||||
#[MaxLength(64)] public String $apiKey;
|
||||
#[MaxLength(64)] public String $token;
|
||||
public \DateTime $validUntil;
|
||||
public User $user;
|
||||
|
||||
public function __construct(?int $id = null) {
|
||||
parent::__construct($id);
|
||||
$this->active = true;
|
||||
}
|
||||
|
||||
public function getValidUntil(): \DateTime {
|
||||
return $this->validUntil;
|
||||
}
|
||||
|
||||
public static function create(User $user, int $days = 30): ApiKey {
|
||||
$apiKey = new ApiKey();
|
||||
$apiKey->user = $user;
|
||||
$apiKey->token = generateRandomString(64);
|
||||
$apiKey->validUntil = (new \DateTime())->modify("+$days days");
|
||||
$apiKey->active = true;
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
public function refresh(SQL $sql, int $days): bool {
|
||||
$this->validUntil = (new \DateTime())->modify("+$days days");
|
||||
return $this->save($sql, ["validUntil"]);
|
||||
|
||||
Reference in New Issue
Block a user