mirror of
https://github.com/elyby/accounts.git
synced 2024-12-25 14:49:46 +05:30
c0aa78d156
Completely removed usage of the RabbitMQ. Queue now based on Redis channels. Worker process now extracted as separate docker container. Base image upgraded to the 1.8.0 version (PHP 7.2.7 and pcntl extension).
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace api\models\authentication;
|
|
|
|
use api\aop\annotations\CollectModelMetrics;
|
|
use api\models\base\ApiForm;
|
|
use api\validators\EmailActivationKeyValidator;
|
|
use common\models\Account;
|
|
use common\models\EmailActivation;
|
|
use Yii;
|
|
use yii\base\ErrorException;
|
|
|
|
class ConfirmEmailForm extends ApiForm {
|
|
|
|
public $key;
|
|
|
|
public function rules(): array {
|
|
return [
|
|
['key', EmailActivationKeyValidator::class, 'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @CollectModelMetrics(prefix="signup.confirmEmail")
|
|
* @return \api\components\User\AuthenticationResult|bool
|
|
* @throws ErrorException
|
|
*/
|
|
public function confirm() {
|
|
if (!$this->validate()) {
|
|
return false;
|
|
}
|
|
|
|
$transaction = Yii::$app->db->beginTransaction();
|
|
|
|
/** @var \common\models\confirmations\RegistrationConfirmation $confirmModel */
|
|
$confirmModel = $this->key;
|
|
$account = $confirmModel->account;
|
|
$account->status = Account::STATUS_ACTIVE;
|
|
if (!$confirmModel->delete()) {
|
|
throw new ErrorException('Unable remove activation key.');
|
|
}
|
|
|
|
if (!$account->save()) {
|
|
throw new ErrorException('Unable activate user account.');
|
|
}
|
|
|
|
$transaction->commit();
|
|
|
|
return Yii::$app->user->createJwtAuthenticationToken($account, true);
|
|
}
|
|
|
|
}
|