+ 'wallabag_url' => $this->getParameter('domain_name'),
+ 'enabled_users' => $this->get('wallabag_user.user_repository')->getSumEnabledUsers(),
+ ]);
+ }
+
+ /**
+ * Enable 2FA using email.
+ *
+ * @Route("/config/otp/email", name="config_otp_email")
+ */
+ public function otpEmailAction()
+ {
+ if (!$this->getParameter('twofactor_auth')) {
+ return $this->createNotFoundException('two_factor not enabled');
+ }
+
+ $user = $this->getUser();
+
+ $user->setGoogleAuthenticatorSecret(null);
+ $user->setBackupCodes(null);
+ $user->setEmailTwoFactor(true);
+
+ $this->container->get('fos_user.user_manager')->updateUser($user, true);
+
+ $this->addFlash(
+ 'notice',
+ 'flashes.config.notice.otp_enabled'
+ );
+
+ return $this->redirect($this->generateUrl('config') . '#set3');
+ }
+
+ /**
+ * Enable 2FA using OTP app, user will need to confirm the generated code from the app.
+ *
+ * @Route("/config/otp/app", name="config_otp_app")
+ */
+ public function otpAppAction()
+ {
+ if (!$this->getParameter('twofactor_auth')) {
+ return $this->createNotFoundException('two_factor not enabled');
+ }
+
+ $user = $this->getUser();
+ $secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret();
+
+ $user->setGoogleAuthenticatorSecret($secret);
+ $user->setEmailTwoFactor(false);
+
+ $backupCodes = (new BackupCodes())->toArray();
+ $backupCodesHashed = array_map(
+ function ($backupCode) {
+ return password_hash($backupCode, PASSWORD_DEFAULT);
+ },
+ $backupCodes
+ );
+
+ $user->setBackupCodes($backupCodesHashed);
+
+ $this->container->get('fos_user.user_manager')->updateUser($user, true);
+
+ return $this->render('WallabagCoreBundle:Config:otp_app.html.twig', [
+ 'backupCodes' => $backupCodes,
+ 'qr_code' => $this->get('scheb_two_factor.security.google_authenticator')->getQRContent($user),