mirror of
https://github.com/elyby/accounts.git
synced 2024-11-26 16:52:02 +05:30
Мигрирована логика блокировки аккаунтов
This commit is contained in:
parent
b57b015f66
commit
72a7f743be
@ -17,13 +17,10 @@ class ActiveUserRule extends AccessRule {
|
|||||||
protected function matchCustom($action) {
|
protected function matchCustom($action) {
|
||||||
$account = $this->getIdentity();
|
$account = $this->getIdentity();
|
||||||
|
|
||||||
return $account->status > Account::STATUS_REGISTERED
|
return $account->status === Account::STATUS_ACTIVE
|
||||||
&& $account->isAgreedWithActualRules();
|
&& $account->isAgreedWithActualRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \api\models\AccountIdentity|null
|
|
||||||
*/
|
|
||||||
protected function getIdentity() {
|
protected function getIdentity() {
|
||||||
return Yii::$app->getUser()->getIdentity();
|
return Yii::$app->getUser()->getIdentity();
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,11 @@ class LoginForm extends ApiForm {
|
|||||||
// TODO: проверить, не заблокирован ли аккаунт
|
// TODO: проверить, не заблокирован ли аккаунт
|
||||||
if (!$this->hasErrors()) {
|
if (!$this->hasErrors()) {
|
||||||
$account = $this->getAccount();
|
$account = $this->getAccount();
|
||||||
if ($account->status !== Account::STATUS_ACTIVE) {
|
if ($account->status === Account::STATUS_BANNED) {
|
||||||
|
$this->addError($attribute, E::ACCOUNT_BANNED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($account->status === Account::STATUS_REGISTERED) {
|
||||||
$this->addError($attribute, E::ACCOUNT_NOT_ACTIVATED);
|
$this->addError($attribute, E::ACCOUNT_NOT_ACTIVATED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ final class Error {
|
|||||||
const KEY_NOT_EXISTS = 'error.key_not_exists';
|
const KEY_NOT_EXISTS = 'error.key_not_exists';
|
||||||
const KEY_EXPIRE = 'error.key_expire';
|
const KEY_EXPIRE = 'error.key_expire';
|
||||||
|
|
||||||
|
const ACCOUNT_BANNED = 'error.account_banned';
|
||||||
const ACCOUNT_NOT_ACTIVATED = 'error.account_not_activated';
|
const ACCOUNT_NOT_ACTIVATED = 'error.account_not_activated';
|
||||||
const ACCOUNT_ALREADY_ACTIVATED = 'error.account_already_activated';
|
const ACCOUNT_ALREADY_ACTIVATED = 'error.account_already_activated';
|
||||||
const ACCOUNT_CANNOT_RESEND_MESSAGE = 'error.account_cannot_resend_message';
|
const ACCOUNT_CANNOT_RESEND_MESSAGE = 'error.account_cannot_resend_message';
|
||||||
|
@ -18,7 +18,13 @@ class ActiveUserRuleTest extends TestCase {
|
|||||||
$account = new AccountIdentity();
|
$account = new AccountIdentity();
|
||||||
|
|
||||||
$this->specify('get false if user not finished registration', function() use (&$account) {
|
$this->specify('get false if user not finished registration', function() use (&$account) {
|
||||||
$account->status = 0;
|
$account->status = Account::STATUS_REGISTERED;
|
||||||
|
$filter = $this->getFilterMock($account);
|
||||||
|
expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->false();
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->specify('get false if user has banned status', function() use (&$account) {
|
||||||
|
$account->status = Account::STATUS_BANNED;
|
||||||
$filter = $this->getFilterMock($account);
|
$filter = $this->getFilterMock($account);
|
||||||
expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->false();
|
expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->false();
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,6 @@ use Codeception\Specify;
|
|||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
use tests\codeception\api\unit\DbTestCase;
|
use tests\codeception\api\unit\DbTestCase;
|
||||||
use tests\codeception\common\fixtures\AccountFixture;
|
use tests\codeception\common\fixtures\AccountFixture;
|
||||||
use Yii;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property AccountFixture $accounts
|
* @property AccountFixture $accounts
|
||||||
@ -84,6 +83,14 @@ class LoginFormTest extends DbTestCase {
|
|||||||
expect($model->getErrors('login'))->equals(['error.account_not_activated']);
|
expect($model->getErrors('login'))->equals(['error.account_not_activated']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->specify('error.account_banned if account has banned status', function () {
|
||||||
|
$model = $this->createModel([
|
||||||
|
'account' => new AccountIdentity(['status' => Account::STATUS_BANNED]),
|
||||||
|
]);
|
||||||
|
$model->validateActivity('login');
|
||||||
|
expect($model->getErrors('login'))->equals(['error.account_banned']);
|
||||||
|
});
|
||||||
|
|
||||||
$this->specify('no errors if account active', function () {
|
$this->specify('no errors if account active', function () {
|
||||||
$model = $this->createModel([
|
$model = $this->createModel([
|
||||||
'account' => new AccountIdentity(['status' => Account::STATUS_ACTIVE]),
|
'account' => new AccountIdentity(['status' => Account::STATUS_ACTIVE]),
|
||||||
|
Loading…
Reference in New Issue
Block a user