From 258011918004ef2920ed6cc52fbab3b999de1b3b Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 28 Feb 2016 00:50:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BD=D0=B5=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B0=D0=BA?= =?UTF-8?q?=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B5=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/LoginForm.php | 11 +++++++++++ tests/codeception/api/functional/LoginCest.php | 9 +++++++++ .../codeception/api/unit/models/LoginFormTest.php | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/api/models/LoginForm.php b/api/models/LoginForm.php index 18ebed8..3f9db42 100644 --- a/api/models/LoginForm.php +++ b/api/models/LoginForm.php @@ -22,6 +22,8 @@ class LoginForm extends BaseApiForm { }, 'message' => 'error.password_required'], ['password', 'validatePassword'], + ['login', 'validateActivity'], + ['rememberMe', 'boolean'], ]; } @@ -43,6 +45,15 @@ class LoginForm extends BaseApiForm { } } + public function validateActivity($attribute) { + if (!$this->hasErrors()) { + $account = $this->getAccount(); + if ($account->status !== Account::STATUS_ACTIVE) { + $this->addError($attribute, 'error.account_not_activated'); + } + } + } + /** * @return bool|string JWT с информацией об аккаунте */ diff --git a/tests/codeception/api/functional/LoginCest.php b/tests/codeception/api/functional/LoginCest.php index 5b86f2d..adff510 100644 --- a/tests/codeception/api/functional/LoginCest.php +++ b/tests/codeception/api/functional/LoginCest.php @@ -35,6 +35,15 @@ class LoginCest { ], ]); + $I->wantTo('see error.account_not_activated expected if credentials are valid, but account is not activated'); + $route->login('howe.garnett', 'password_0'); + $I->canSeeResponseContainsJson([ + 'success' => false, + 'errors' => [ + 'login' => 'error.account_not_activated', + ], + ]); + $I->wantTo('don\'t see errors on login field if username is correct and exists in database'); $route->login('Admin'); $I->canSeeResponseContainsJson([ diff --git a/tests/codeception/api/unit/models/LoginFormTest.php b/tests/codeception/api/unit/models/LoginFormTest.php index 0f138fb..bc9dc97 100644 --- a/tests/codeception/api/unit/models/LoginFormTest.php +++ b/tests/codeception/api/unit/models/LoginFormTest.php @@ -40,10 +40,20 @@ class LoginFormTest extends DbTestCase { expect('model should not login user', $model->login())->false(); expect('error messages should be set', $model->errors)->notEmpty(); }); + + $model = $this->createModel($this->accounts['not-activated-account']['username'], 'password_0'); + $this->specify('get error if account data valid, but account is not activated', function () use ($model) { + expect('model should not login user', $model->login())->false(); + expect('error messages should be set', $model->errors)->equals([ + 'login' => [ + 'error.account_not_activated', + ], + ]); + }); } public function testLoginByUsernameCorrect() { - $model = $this->createModel('Admin', 'password_0'); + $model = $this->createModel($this->accounts['admin']['username'], 'password_0'); $this->specify('user should be able to login with correct username and password', function () use ($model) { expect('model should login user', $model->login())->notEquals(false); expect('error message should not be set', $model->errors)->isEmpty(); @@ -51,7 +61,7 @@ class LoginFormTest extends DbTestCase { } public function testLoginByEmailCorrect() { - $model = $this->createModel('admin@ely.by', 'password_0'); + $model = $this->createModel($this->accounts['admin']['email'], 'password_0'); $this->specify('user should be able to login with correct email and password', function () use ($model) { expect('model should login user', $model->login())->notEquals(false); expect('error message should not be set', $model->errors)->isEmpty();