mirror of
https://github.com/openvk/openvk
synced 2025-02-02 21:15:42 +03:00
Alexander Minkin
6ec54a379d
* feat(lint): add php-cs-fixer for linting Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0. This is not the reformatting commit. * style: format code according to PER-CS 2.0 with php-cs-fixer * ci(actions): add lint action Resolves #1132.
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Repositories;
|
|
|
|
use openvk\Web\Models\Entities\APIToken;
|
|
|
|
class APITokens extends Repository
|
|
{
|
|
protected $tableName = "api_tokens";
|
|
protected $modelName = "APIToken";
|
|
|
|
public function getByCode(string $code, bool $withRevoked = false): ?APIToken
|
|
{
|
|
$parts = explode("-", $code);
|
|
$id = $parts[0];
|
|
$secret = implode("", array_slice($parts, 1, 9));
|
|
|
|
$token = $this->get((int) $id);
|
|
if (!$token) {
|
|
return null;
|
|
} elseif ($token->getSecret() !== $secret) {
|
|
return null;
|
|
} elseif ($token->isRevoked() && !$withRevoked) {
|
|
return null;
|
|
}
|
|
|
|
return $token;
|
|
}
|
|
|
|
public function getStaleByUser(int $userId, string $platform, bool $withRevoked = false): ?APIToken
|
|
{
|
|
return $this->toEntity($this->table->where([
|
|
'user' => $userId,
|
|
'platform' => $platform,
|
|
'deleted' => $withRevoked,
|
|
])->fetch());
|
|
}
|
|
}
|