mirror of
https://github.com/elyby/accounts.git
synced 2024-12-11 16:09:25 +05:30
37 lines
907 B
PHP
37 lines
907 B
PHP
<?php
|
|
namespace api\modules\authserver\models;
|
|
|
|
use api\models\base\ApiForm;
|
|
use api\modules\authserver\exceptions\ForbiddenOperationException;
|
|
use api\modules\authserver\validators\RequiredValidator;
|
|
use common\models\MinecraftAccessKey;
|
|
|
|
class ValidateForm extends ApiForm {
|
|
|
|
public $accessToken;
|
|
|
|
public function rules() {
|
|
return [
|
|
[['accessToken'], RequiredValidator::class],
|
|
];
|
|
}
|
|
|
|
public function validateToken() : bool {
|
|
$this->validate();
|
|
|
|
/** @var MinecraftAccessKey|null $result */
|
|
$result = MinecraftAccessKey::findOne($this->accessToken);
|
|
if ($result === null) {
|
|
throw new ForbiddenOperationException('Invalid token.');
|
|
}
|
|
|
|
if ($result->isExpired()) {
|
|
$result->delete();
|
|
throw new ForbiddenOperationException('Token expired.');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|