mirror of
https://github.com/elyby/accounts.git
synced 2024-12-27 07:30:18 +05:30
Добавил генерацию jwt токена для формы подтверждения регистрации
This commit is contained in:
parent
5be5a732bd
commit
d1cdb847e0
@ -52,20 +52,16 @@ class SignupController extends Controller {
|
|||||||
public function actionConfirm() {
|
public function actionConfirm() {
|
||||||
$model = new ConfirmEmailForm();
|
$model = new ConfirmEmailForm();
|
||||||
$model->load(Yii::$app->request->post());
|
$model->load(Yii::$app->request->post());
|
||||||
if (!$model->confirm()) {
|
if (!($jwt = $model->confirm())) {
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: не уверен, что логин должен быть здесь + нужно разобраться с параметрами установки куки авторизации и сессии
|
|
||||||
$activationCode = $model->getActivationCodeModel();
|
|
||||||
$account = $activationCode->account;
|
|
||||||
Yii::$app->user->login($account);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
|
'jwt' => $jwt,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,14 @@ class ConfirmEmailForm extends BaseKeyConfirmationForm {
|
|||||||
$transaction->commit();
|
$transaction->commit();
|
||||||
} catch (ErrorException $e) {
|
} catch (ErrorException $e) {
|
||||||
$transaction->rollBack();
|
$transaction->rollBack();
|
||||||
|
if (YII_DEBUG) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return $account->getJWT();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ class EmailConfirmationCest {
|
|||||||
'success' => true,
|
'success' => true,
|
||||||
]);
|
]);
|
||||||
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
|
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
|
||||||
|
$I->canSeeResponseJsonMatchesJsonPath('$.jwt');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class ConfirmEmailFormTest extends DbTestCase {
|
|||||||
$fixture = $this->emailActivations[0];
|
$fixture = $this->emailActivations[0];
|
||||||
$model = $this->createModel($fixture['key']);
|
$model = $this->createModel($fixture['key']);
|
||||||
$this->specify('expect true result', function() use ($model, $fixture) {
|
$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();
|
expect('email activation key is not exist', EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists())->false();
|
||||||
/** @var Account $user */
|
/** @var Account $user */
|
||||||
$user = Account::findOne($fixture['account_id']);
|
$user = Account::findOne($fixture['account_id']);
|
||||||
|
Loading…
Reference in New Issue
Block a user