aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Controller
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2019-01-30 01:02:27 +0100
committerGitHub <noreply@github.com>2019-01-30 01:02:27 +0100
commit2e5b3fa361098498a9e42a65396a27e1eb487fba (patch)
treef20677c3d68c1ea756f0835ff179a0d7d3431a67 /src/Wallabag/UserBundle/Controller
parentc6024246b744e411175318065f7c396bbb5a213e (diff)
parent4654a83b6438b88e3b7062a21d18999d9df2fb8e (diff)
downloadwallabag-2e5b3fa361098498a9e42a65396a27e1eb487fba.tar.gz
wallabag-2e5b3fa361098498a9e42a65396a27e1eb487fba.tar.zst
wallabag-2e5b3fa361098498a9e42a65396a27e1eb487fba.zip
Merge pull request #3798 from wallabag/update-two-factor-bundle
Enable OTP 2FA
Diffstat (limited to 'src/Wallabag/UserBundle/Controller')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php
index a9746fb4..63a06206 100644
--- a/src/Wallabag/UserBundle/Controller/ManageController.php
+++ b/src/Wallabag/UserBundle/Controller/ManageController.php
@@ -62,14 +62,29 @@ class ManageController extends Controller
62 */ 62 */
63 public function editAction(Request $request, User $user) 63 public function editAction(Request $request, User $user)
64 { 64 {
65 $userManager = $this->container->get('fos_user.user_manager');
66
65 $deleteForm = $this->createDeleteForm($user); 67 $deleteForm = $this->createDeleteForm($user);
66 $editForm = $this->createForm('Wallabag\UserBundle\Form\UserType', $user); 68 $form = $this->createForm('Wallabag\UserBundle\Form\UserType', $user);
67 $editForm->handleRequest($request); 69 $form->handleRequest($request);
68 70
69 if ($editForm->isSubmitted() && $editForm->isValid()) { 71 // `googleTwoFactor` isn't a field within the User entity, we need to define it's value in a different way
70 $em = $this->getDoctrine()->getManager(); 72 if ($this->getParameter('twofactor_auth') && true === $user->isGoogleAuthenticatorEnabled() && false === $form->isSubmitted()) {
71 $em->persist($user); 73 $form->get('googleTwoFactor')->setData(true);
72 $em->flush(); 74 }
75
76 if ($form->isSubmitted() && $form->isValid()) {
77 // handle creation / reset of the OTP secret if checkbox changed from the previous state
78 if ($this->getParameter('twofactor_auth')) {
79 if (true === $form->get('googleTwoFactor')->getData() && false === $user->isGoogleAuthenticatorEnabled()) {
80 $user->setGoogleAuthenticatorSecret($this->get('scheb_two_factor.security.google_authenticator')->generateSecret());
81 $user->setEmailTwoFactor(false);
82 } elseif (false === $form->get('googleTwoFactor')->getData() && true === $user->isGoogleAuthenticatorEnabled()) {
83 $user->setGoogleAuthenticatorSecret(null);
84 }
85 }
86
87 $userManager->updateUser($user);
73 88
74 $this->get('session')->getFlashBag()->add( 89 $this->get('session')->getFlashBag()->add(
75 'notice', 90 'notice',
@@ -81,7 +96,7 @@ class ManageController extends Controller
81 96
82 return $this->render('WallabagUserBundle:Manage:edit.html.twig', [ 97 return $this->render('WallabagUserBundle:Manage:edit.html.twig', [
83 'user' => $user, 98 'user' => $user,
84 'edit_form' => $editForm->createView(), 99 'edit_form' => $form->createView(),
85 'delete_form' => $deleteForm->createView(), 100 'delete_form' => $deleteForm->createView(),
86 'twofactor_auth' => $this->getParameter('twofactor_auth'), 101 'twofactor_auth' => $this->getParameter('twofactor_auth'),
87 ]); 102 ]);
@@ -131,8 +146,6 @@ class ManageController extends Controller
131 $form->handleRequest($request); 146 $form->handleRequest($request);
132 147
133 if ($form->isSubmitted() && $form->isValid()) { 148 if ($form->isSubmitted() && $form->isValid()) {
134 $this->get('logger')->info('searching users');
135
136 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); 149 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
137 150
138 $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); 151 $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm);
@@ -157,7 +170,7 @@ class ManageController extends Controller
157 } 170 }
158 171
159 /** 172 /**
160 * Creates a form to delete a User entity. 173 * Create a form to delete a User entity.
161 * 174 *
162 * @param User $user The User entity 175 * @param User $user The User entity
163 * 176 *