+
+ /**
+ * Create a form to create or edit a User entity.
+ *
+ * @param string $type Might be NewUserType or UserType
+ * @param User $user The new / edit user
+ * @param Request $request The request
+ *
+ * @return FormInterface
+ */
+ private function createEditForm($type, User $user, Request $request)
+ {
+ $form = $this->createForm('Wallabag\UserBundle\Form\\' . $type, $user);
+ $form->handleRequest($request);
+
+ // `googleTwoFactor` isn't a field within the User entity, we need to define it's value in a different way
+ if (true === $user->isGoogleAuthenticatorEnabled() && false === $form->isSubmitted()) {
+ $form->get('googleTwoFactor')->setData(true);
+ }
+
+ return $form;
+ }
+
+ /**
+ * Handle OTP update, taking care to only have one 2fa enable at a time.
+ *
+ * @see ConfigController
+ *
+ * @param FormInterface $form
+ * @param User $user
+ *
+ * @return User
+ */
+ private function handleOtp(FormInterface $form, User $user)
+ {
+ if (true === $form->get('googleTwoFactor')->getData() && false === $user->isGoogleAuthenticatorEnabled()) {
+ $user->setGoogleAuthenticatorSecret($this->get('scheb_two_factor.security.google_authenticator')->generateSecret());
+ $user->setEmailTwoFactor(false);
+
+ return $user;
+ }
+
+ $user->setGoogleAuthenticatorSecret(null);
+
+ return $user;
+ }