From d1cdb847e0578229438a7ad769f387366fef078d Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 27 Feb 2016 01:37:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20jwt=20?= =?UTF-8?q?=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D0=BF=D0=BE=D0=B4=D1=82=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/SignupController.php | 8 ++------ api/models/ConfirmEmailForm.php | 8 ++++++-- .../codeception/api/functional/EmailConfirmationCest.php | 1 + .../codeception/api/unit/models/ConfirmEmailFormTest.php | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/api/controllers/SignupController.php b/api/controllers/SignupController.php index b7b5fcb..db0853d 100644 --- a/api/controllers/SignupController.php +++ b/api/controllers/SignupController.php @@ -52,20 +52,16 @@ class SignupController extends Controller { public function actionConfirm() { $model = new ConfirmEmailForm(); $model->load(Yii::$app->request->post()); - if (!$model->confirm()) { + if (!($jwt = $model->confirm())) { return [ 'success' => false, 'errors' => $this->normalizeModelErrors($model->getErrors()), ]; } - // TODO: не уверен, что логин должен быть здесь + нужно разобраться с параметрами установки куки авторизации и сессии - $activationCode = $model->getActivationCodeModel(); - $account = $activationCode->account; - Yii::$app->user->login($account); - return [ 'success' => true, + 'jwt' => $jwt, ]; } diff --git a/api/models/ConfirmEmailForm.php b/api/models/ConfirmEmailForm.php index e62641e..c9d454f 100644 --- a/api/models/ConfirmEmailForm.php +++ b/api/models/ConfirmEmailForm.php @@ -35,10 +35,14 @@ class ConfirmEmailForm extends BaseKeyConfirmationForm { $transaction->commit(); } catch (ErrorException $e) { $transaction->rollBack(); - throw $e; + if (YII_DEBUG) { + throw $e; + } else { + return false; + } } - return true; + return $account->getJWT(); } } diff --git a/tests/codeception/api/functional/EmailConfirmationCest.php b/tests/codeception/api/functional/EmailConfirmationCest.php index f503113..c3d563d 100644 --- a/tests/codeception/api/functional/EmailConfirmationCest.php +++ b/tests/codeception/api/functional/EmailConfirmationCest.php @@ -36,6 +36,7 @@ class EmailConfirmationCest { 'success' => true, ]); $I->cantSeeResponseJsonMatchesJsonPath('$.errors'); + $I->canSeeResponseJsonMatchesJsonPath('$.jwt'); } } diff --git a/tests/codeception/api/unit/models/ConfirmEmailFormTest.php b/tests/codeception/api/unit/models/ConfirmEmailFormTest.php index e101fdb..92b9029 100644 --- a/tests/codeception/api/unit/models/ConfirmEmailFormTest.php +++ b/tests/codeception/api/unit/models/ConfirmEmailFormTest.php @@ -34,7 +34,7 @@ class ConfirmEmailFormTest extends DbTestCase { $fixture = $this->emailActivations[0]; $model = $this->createModel($fixture['key']); $this->specify('expect true result', function() use ($model, $fixture) { - expect('model return successful result', $model->confirm())->true(); + expect('model return successful result', $model->confirm())->notEquals(false); expect('email activation key is not exist', EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists())->false(); /** @var Account $user */ $user = Account::findOne($fixture['account_id']);