2016-08-21 04:51:39 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\authserver\models;
|
|
|
|
|
2017-05-31 05:40:22 +05:30
|
|
|
use api\models\base\ApiForm;
|
2016-08-21 04:51:39 +05:30
|
|
|
use api\modules\authserver\exceptions\ForbiddenOperationException;
|
|
|
|
use api\modules\authserver\validators\RequiredValidator;
|
2016-09-01 13:01:43 +05:30
|
|
|
use common\models\Account;
|
2016-08-21 04:51:39 +05:30
|
|
|
use common\models\MinecraftAccessKey;
|
|
|
|
|
2017-05-31 05:40:22 +05:30
|
|
|
class RefreshTokenForm extends ApiForm {
|
2016-08-21 04:51:39 +05:30
|
|
|
|
|
|
|
public $accessToken;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
public $clientToken;
|
|
|
|
|
|
|
|
public function rules() {
|
|
|
|
return [
|
2016-09-01 13:01:43 +05:30
|
|
|
[['accessToken', 'clientToken'], RequiredValidator::class],
|
2016-08-21 04:51:39 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return AuthenticateData
|
|
|
|
* @throws \api\modules\authserver\exceptions\AuthserverException
|
|
|
|
*/
|
|
|
|
public function refresh() {
|
|
|
|
$this->validate();
|
|
|
|
|
|
|
|
/** @var MinecraftAccessKey|null $accessToken */
|
|
|
|
$accessToken = MinecraftAccessKey::findOne([
|
|
|
|
'access_token' => $this->accessToken,
|
|
|
|
'client_token' => $this->clientToken,
|
|
|
|
]);
|
|
|
|
if ($accessToken === null) {
|
|
|
|
throw new ForbiddenOperationException('Invalid token.');
|
|
|
|
}
|
|
|
|
|
2016-09-01 13:01:43 +05:30
|
|
|
if ($accessToken->account->status === Account::STATUS_BANNED) {
|
|
|
|
throw new ForbiddenOperationException('This account has been suspended.');
|
|
|
|
}
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
$accessToken->refreshPrimaryKeyValue();
|
|
|
|
$accessToken->update();
|
|
|
|
|
|
|
|
$dataModel = new AuthenticateData($accessToken);
|
|
|
|
|
|
|
|
return $dataModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|