mirror of
https://github.com/elyby/accounts.git
synced 2024-12-26 07:09:46 +05:30
Добавлена ошибка для неактивированных аккаунтов при попытке логина
This commit is contained in:
parent
5c056710bc
commit
2580119180
@ -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 с информацией об аккаунте
|
||||
*/
|
||||
|
@ -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([
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user