/** * Creates a form model given a token. * * @param string $token * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if token is empty or not valid */ public function __construct($token, $config = []) { if (empty($token) || !is_string($token)) { throw new InvalidParamException('Password reset token cannot be blank.'); } /** @var UserToken $tokenModel */ $this->token = UserToken::find()->notExpired()->byType(UserToken::TYPE_PASSWORD_RESET)->byToken($token)->one(); if (!$this->token) { throw new InvalidParamException('Wrong password reset token.'); } parent::__construct($config); }
public function actionActivation($token) { $token = UserToken::find()->byType(UserToken::TYPE_ACTIVATION)->byToken($token)->notExpired()->one(); if (!$token) { throw new BadRequestHttpException(); } $user = $token->user; $user->updateAttributes(['is_activated' => true]); $token->delete(); Yii::$app->getUser()->login($user); Yii::$app->getSession()->setFlash('alert', ['body' => Yii::t('frontend', 'Your account has been successfully activated.'), 'options' => ['class' => 'alert-success']]); return $this->goHome(); }