From 6b04860f0efd9e8283f3f07d282239f43bd43f67 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 13 Mar 2016 21:46:22 +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=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=20email=20=D0=BF=D1=80=D0=B8=20=D0=B2=D1=85=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=20=D0=B2=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=D0=B9=20=D0=B0=D0=BA?= =?UTF-8?q?=D0=BA=D0=B0=D1=83=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/AuthenticationController.php | 8 +++++++- api/models/LoginForm.php | 2 +- tests/codeception/api/functional/LoginCest.php | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) 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');