diff --git a/api/controllers/AuthenticationController.php b/api/controllers/AuthenticationController.php index f6f5240..5d0ba23 100644 --- a/api/controllers/AuthenticationController.php +++ b/api/controllers/AuthenticationController.php @@ -36,10 +36,16 @@ class AuthenticationController extends Controller { $model = new LoginForm(); $model->load(Yii::$app->request->post()); if (($jwt = $model->login()) === false) { - return [ + $data = [ 'success' => false, 'errors' => $this->normalizeModelErrors($model->getErrors()), ]; + + if (ArrayHelper::getValue($data['errors'], 'login') === 'error.account_not_activated') { + $data['data']['email'] = $model->getAccount()->email; + } + + return $data; } return [ diff --git a/api/models/LoginForm.php b/api/models/LoginForm.php index 3f9db42..a123560 100644 --- a/api/models/LoginForm.php +++ b/api/models/LoginForm.php @@ -68,7 +68,7 @@ class LoginForm extends BaseApiForm { /** * @return Account|null */ - protected function getAccount() { + public function getAccount() { if ($this->_account === NULL) { $attribute = strpos($this->login, '@') ? 'email' : 'username'; $this->_account = Account::findOne([$attribute => $this->login]); diff --git a/tests/codeception/api/functional/LoginCest.php b/tests/codeception/api/functional/LoginCest.php index adff510..73c6eb8 100644 --- a/tests/codeception/api/functional/LoginCest.php +++ b/tests/codeception/api/functional/LoginCest.php @@ -43,6 +43,7 @@ class LoginCest { 'login' => 'error.account_not_activated', ], ]); + $I->canSeeResponseJsonMatchesJsonPath('$.data.email'); $I->wantTo('don\'t see errors on login field if username is correct and exists in database'); $route->login('Admin');