mirror of
https://github.com/openvk/openvk
synced 2024-11-14 02:59:12 +03:00
26 lines
732 B
PHP
26 lines
732 B
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";
|
|
|
|
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;
|
|
else if($token->getSecret() !== $secret)
|
|
return NULL;
|
|
else if($token->isRevoked() && !$withRevoked)
|
|
return NULL;
|
|
|
|
return $token;
|
|
}
|
|
}
|