Добавлена ошибка для неактивированных аккаунтов при попытке логина

This commit is contained in:
ErickSkrauch 2016-02-28 00:50:49 +03:00
parent 5c056710bc
commit 2580119180
3 changed files with 32 additions and 2 deletions

View File

@ -22,6 +22,8 @@ class LoginForm extends BaseApiForm {
}, 'message' => 'error.password_required'], }, 'message' => 'error.password_required'],
['password', 'validatePassword'], ['password', 'validatePassword'],
['login', 'validateActivity'],
['rememberMe', 'boolean'], ['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 с информацией об аккаунте * @return bool|string JWT с информацией об аккаунте
*/ */

View File

@ -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'); $I->wantTo('don\'t see errors on login field if username is correct and exists in database');
$route->login('Admin'); $route->login('Admin');
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([

View File

@ -40,10 +40,20 @@ class LoginFormTest extends DbTestCase {
expect('model should not login user', $model->login())->false(); expect('model should not login user', $model->login())->false();
expect('error messages should be set', $model->errors)->notEmpty(); 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() { 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) { $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('model should login user', $model->login())->notEquals(false);
expect('error message should not be set', $model->errors)->isEmpty(); expect('error message should not be set', $model->errors)->isEmpty();
@ -51,7 +61,7 @@ class LoginFormTest extends DbTestCase {
} }
public function testLoginByEmailCorrect() { 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) { $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('model should login user', $model->login())->notEquals(false);
expect('error message should not be set', $model->errors)->isEmpty(); expect('error message should not be set', $model->errors)->isEmpty();