mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Перенесены тесты со старого authserver, исправлены ошибки в коде
This commit is contained in:
@ -6,6 +6,10 @@ use yii\base\Model;
|
||||
|
||||
abstract class Form extends Model {
|
||||
|
||||
public function formName() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function loadByGet() {
|
||||
return $this->load(Yii::$app->request->get());
|
||||
}
|
||||
|
@ -3,18 +3,17 @@ namespace api\modules\authserver\models;
|
||||
|
||||
use api\modules\authserver\exceptions\ForbiddenOperationException;
|
||||
use api\modules\authserver\validators\RequiredValidator;
|
||||
use common\models\Account;
|
||||
use common\models\MinecraftAccessKey;
|
||||
|
||||
class RefreshTokenForm extends Form {
|
||||
|
||||
public $accessToken;
|
||||
public $clientToken;
|
||||
public $selectedProfile;
|
||||
public $requestUser;
|
||||
|
||||
public function rules() {
|
||||
return [
|
||||
[['accessToken', 'clientToken', 'selectedProfile', 'requestUser'], RequiredValidator::class],
|
||||
[['accessToken', 'clientToken'], RequiredValidator::class],
|
||||
];
|
||||
}
|
||||
|
||||
@ -34,6 +33,10 @@ class RefreshTokenForm extends Form {
|
||||
throw new ForbiddenOperationException('Invalid token.');
|
||||
}
|
||||
|
||||
if ($accessToken->account->status === Account::STATUS_BANNED) {
|
||||
throw new ForbiddenOperationException('This account has been suspended.');
|
||||
}
|
||||
|
||||
$accessToken->refreshPrimaryKeyValue();
|
||||
$accessToken->update();
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace api\modules\authserver\models;
|
||||
use api\models\authentication\LoginForm;
|
||||
use api\modules\authserver\exceptions\ForbiddenOperationException;
|
||||
use api\modules\authserver\validators\RequiredValidator;
|
||||
use common\helpers\Error as E;
|
||||
use common\models\MinecraftAccessKey;
|
||||
use Yii;
|
||||
|
||||
@ -25,6 +26,12 @@ class SignoutForm extends Form {
|
||||
$loginForm->login = $this->username;
|
||||
$loginForm->password = $this->password;
|
||||
if (!$loginForm->validate()) {
|
||||
$errors = $loginForm->getFirstErrors();
|
||||
if (isset($errors['login']) && $errors['login'] === E::ACCOUNT_BANNED) {
|
||||
// Считаем, что заблокированный может безболезненно выйти
|
||||
return true;
|
||||
}
|
||||
|
||||
// На старом сервере авторизации использовалось поле nickname, а не username, так что сохраняем эту логику
|
||||
$attribute = $loginForm->getLoginAttribute();
|
||||
if ($attribute === 'username') {
|
||||
|
Reference in New Issue
Block a user