validate()) { return false; } $confirmModel = $this->getActivationCodeModel(); if ($confirmModel->type !== EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION) { $confirmModel->delete(); // TODO: вот где-то здесь нужно ещё попутно сгенерировать соответствующую ошибку return false; } $transaction = Yii::$app->db->beginTransaction(); try { $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.'); } $changeUsernameForm = new ChangeUsernameForm(); $changeUsernameForm->createEventTask($account->id, $account->username, null); $transaction->commit(); } catch (ErrorException $e) { $transaction->rollBack(); if (YII_DEBUG) { throw $e; } else { return false; } } /** @var \api\components\User\Component $component */ $component = Yii::$app->user; return $component->login(new AccountIdentity($account->attributes), true); } }