/** * Verify email by one-time token * * @param $token string * @return \yii\web\Response */ public function actionVerifyEmail($token) { $user = User::findByVerificationToken($token, User::STATUS_PENDING); if (!$user) { Yii::$app->session->addFlash('error', Yii::t('auth', 'The verification token you have provided is invalid.')); return $this->goHome(); } if (!$user->activate()) { Yii::error('Failed to verify user with ID #' . $user->id . ' User errors: ' . json_encode($user->getErrors()), 'auth'); Yii::$app->session->addFlash('error', Yii::t('auth', 'An error occurred during email verification. Please contact site administrator for more details.')); return $this->redirect(['index']); } if (!Yii::$app->user->login($user)) { Yii::error('Failed to login user with ID #' . $user->id, 'auth'); Yii::$app->session->addFlash('error', Yii::t('auth', 'An error occurred during automatic login. Please try to login manually.')); return $this->redirect(['auth']); } Yii::$app->session->addFlash('success', Yii::t('auth', 'You have successfully verified your email address.')); return $this->goHome(); }