2016-08-21 04:51:39 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\authserver\models;
|
|
|
|
|
|
|
|
use api\modules\authserver\exceptions\ForbiddenOperationException;
|
|
|
|
use api\modules\authserver\validators\RequiredValidator;
|
|
|
|
use common\models\MinecraftAccessKey;
|
|
|
|
|
|
|
|
class ValidateForm extends Form {
|
|
|
|
|
|
|
|
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.');
|
|
|
|
}
|
|
|
|
|
2016-09-03 04:24:22 +05:30
|
|
|
if ($result->isExpired()) {
|
2016-08-21 04:51:39 +05:30
|
|
|
$result->delete();
|
|
|
|
throw new ForbiddenOperationException('Token expired.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|