/**
* Enable 2FA using email.
*
- * @param Request $request
- *
* @Route("/config/otp/email", name="config_otp_email")
*/
- public function otpEmailAction(Request $request)
+ public function otpEmailAction()
{
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);
- if (!$user->isGoogleTwoFactor()) {
- $secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret();
+ $backupCodes = (new BackupCodes())->toArray();
+ $backupCodesHashed = array_map(
+ function ($backupCode) {
+ return password_hash($backupCode, PASSWORD_DEFAULT);
+ },
+ $backupCodes
+ );
- $user->setGoogleAuthenticatorSecret($secret);
- $user->setEmailTwoFactor(false);
- $user->setBackupCodes((new BackupCodes())->toArray());
+ $user->setBackupCodes($backupCodesHashed);
- $this->container->get('fos_user.user_manager')->updateUser($user, true);
- }
+ $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),
]);
}