From 72a7f743bed8c2710b84a9c340f6a9d2d99e7f35 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 22 Aug 2016 00:09:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B8=D0=B3=D1=80=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/filters/ActiveUserRule.php | 5 +---- api/models/authentication/LoginForm.php | 6 +++++- common/helpers/Error.php | 1 + .../codeception/api/unit/filters/ActiveUserRuleTest.php | 8 +++++++- .../api/unit/models/authentication/LoginFormTest.php | 9 ++++++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/api/filters/ActiveUserRule.php b/api/filters/ActiveUserRule.php index 4b803bd..e50150e 100644 --- a/api/filters/ActiveUserRule.php +++ b/api/filters/ActiveUserRule.php @@ -17,13 +17,10 @@ class ActiveUserRule extends AccessRule { protected function matchCustom($action) { $account = $this->getIdentity(); - return $account->status > Account::STATUS_REGISTERED + return $account->status === Account::STATUS_ACTIVE && $account->isAgreedWithActualRules(); } - /** - * @return \api\models\AccountIdentity|null - */ protected function getIdentity() { return Yii::$app->getUser()->getIdentity(); } diff --git a/api/models/authentication/LoginForm.php b/api/models/authentication/LoginForm.php index 485bbb3..c860d02 100644 --- a/api/models/authentication/LoginForm.php +++ b/api/models/authentication/LoginForm.php @@ -55,7 +55,11 @@ class LoginForm extends ApiForm { // TODO: проверить, не заблокирован ли аккаунт if (!$this->hasErrors()) { $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); } } diff --git a/common/helpers/Error.php b/common/helpers/Error.php index b14b944..664daa7 100644 --- a/common/helpers/Error.php +++ b/common/helpers/Error.php @@ -27,6 +27,7 @@ final class Error { const KEY_NOT_EXISTS = 'error.key_not_exists'; const KEY_EXPIRE = 'error.key_expire'; + const ACCOUNT_BANNED = 'error.account_banned'; const ACCOUNT_NOT_ACTIVATED = 'error.account_not_activated'; const ACCOUNT_ALREADY_ACTIVATED = 'error.account_already_activated'; const ACCOUNT_CANNOT_RESEND_MESSAGE = 'error.account_cannot_resend_message'; diff --git a/tests/codeception/api/unit/filters/ActiveUserRuleTest.php b/tests/codeception/api/unit/filters/ActiveUserRuleTest.php index d48f29a..faa5b20 100644 --- a/tests/codeception/api/unit/filters/ActiveUserRuleTest.php +++ b/tests/codeception/api/unit/filters/ActiveUserRuleTest.php @@ -18,7 +18,13 @@ class ActiveUserRuleTest extends TestCase { $account = new AccountIdentity(); $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); expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->false(); }); diff --git a/tests/codeception/api/unit/models/authentication/LoginFormTest.php b/tests/codeception/api/unit/models/authentication/LoginFormTest.php index 372653e..625b08b 100644 --- a/tests/codeception/api/unit/models/authentication/LoginFormTest.php +++ b/tests/codeception/api/unit/models/authentication/LoginFormTest.php @@ -8,7 +8,6 @@ use Codeception\Specify; use common\models\Account; use tests\codeception\api\unit\DbTestCase; use tests\codeception\common\fixtures\AccountFixture; -use Yii; /** * @property AccountFixture $accounts @@ -84,6 +83,14 @@ class LoginFormTest extends DbTestCase { 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 () { $model = $this->createModel([ 'account' => new AccountIdentity(['status' => Account::STATUS_ACTIVE]),