diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-05-29 11:14:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 11:14:00 +0200 |
commit | 73ec68b1ffafb792265a3805833e5cd84c966aed (patch) | |
tree | 33c6040c050f85c537f8dbf5e91d8c281db092cd /src/Wallabag/UserBundle/Controller | |
parent | 2ba365c7c49556cd23b444dc3bb8d4a8cf08809d (diff) | |
parent | 2cbee36a0184786644470a84fdd8c720cfcac58e (diff) | |
download | wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.tar.gz wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.tar.zst wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.zip |
Merge pull request #3984 from wallabag/2.4
Merge 2.4 into master
Diffstat (limited to 'src/Wallabag/UserBundle/Controller')
-rw-r--r-- | src/Wallabag/UserBundle/Controller/ManageController.php | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index f3de656f..63a06206 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php | |||
@@ -7,10 +7,9 @@ use FOS\UserBundle\FOSUserEvents; | |||
7 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 7 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
8 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 8 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
9 | use Pagerfanta\Pagerfanta; | 9 | use Pagerfanta\Pagerfanta; |
10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
11 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
12 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 10 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
13 | use Symfony\Component\HttpFoundation\Request; | 11 | use Symfony\Component\HttpFoundation\Request; |
12 | use Symfony\Component\Routing\Annotation\Route; | ||
14 | use Wallabag\UserBundle\Entity\User; | 13 | use Wallabag\UserBundle\Entity\User; |
15 | use Wallabag\UserBundle\Form\SearchUserType; | 14 | use Wallabag\UserBundle\Form\SearchUserType; |
16 | 15 | ||
@@ -22,8 +21,7 @@ class ManageController extends Controller | |||
22 | /** | 21 | /** |
23 | * Creates a new User entity. | 22 | * Creates a new User entity. |
24 | * | 23 | * |
25 | * @Route("/new", name="user_new") | 24 | * @Route("/new", name="user_new", methods={"GET", "POST"}) |
26 | * @Method({"GET", "POST"}) | ||
27 | */ | 25 | */ |
28 | public function newAction(Request $request) | 26 | public function newAction(Request $request) |
29 | { | 27 | { |
@@ -60,19 +58,33 @@ class ManageController extends Controller | |||
60 | /** | 58 | /** |
61 | * Displays a form to edit an existing User entity. | 59 | * Displays a form to edit an existing User entity. |
62 | * | 60 | * |
63 | * @Route("/{id}/edit", name="user_edit") | 61 | * @Route("/{id}/edit", name="user_edit", methods={"GET", "POST"}) |
64 | * @Method({"GET", "POST"}) | ||
65 | */ | 62 | */ |
66 | public function editAction(Request $request, User $user) | 63 | public function editAction(Request $request, User $user) |
67 | { | 64 | { |
65 | $userManager = $this->container->get('fos_user.user_manager'); | ||
66 | |||
68 | $deleteForm = $this->createDeleteForm($user); | 67 | $deleteForm = $this->createDeleteForm($user); |
69 | $editForm = $this->createForm('Wallabag\UserBundle\Form\UserType', $user); | 68 | $form = $this->createForm('Wallabag\UserBundle\Form\UserType', $user); |
70 | $editForm->handleRequest($request); | 69 | $form->handleRequest($request); |
71 | 70 | ||
72 | 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 |
73 | $em = $this->getDoctrine()->getManager(); | 72 | if ($this->getParameter('twofactor_auth') && true === $user->isGoogleAuthenticatorEnabled() && false === $form->isSubmitted()) { |
74 | $em->persist($user); | 73 | $form->get('googleTwoFactor')->setData(true); |
75 | $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); | ||
76 | 88 | ||
77 | $this->get('session')->getFlashBag()->add( | 89 | $this->get('session')->getFlashBag()->add( |
78 | 'notice', | 90 | 'notice', |
@@ -84,7 +96,7 @@ class ManageController extends Controller | |||
84 | 96 | ||
85 | return $this->render('WallabagUserBundle:Manage:edit.html.twig', [ | 97 | return $this->render('WallabagUserBundle:Manage:edit.html.twig', [ |
86 | 'user' => $user, | 98 | 'user' => $user, |
87 | 'edit_form' => $editForm->createView(), | 99 | 'edit_form' => $form->createView(), |
88 | 'delete_form' => $deleteForm->createView(), | 100 | 'delete_form' => $deleteForm->createView(), |
89 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), | 101 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), |
90 | ]); | 102 | ]); |
@@ -93,8 +105,7 @@ class ManageController extends Controller | |||
93 | /** | 105 | /** |
94 | * Deletes a User entity. | 106 | * Deletes a User entity. |
95 | * | 107 | * |
96 | * @Route("/{id}", name="user_delete") | 108 | * @Route("/{id}", name="user_delete", methods={"DELETE"}) |
97 | * @Method("DELETE") | ||
98 | */ | 109 | */ |
99 | public function deleteAction(Request $request, User $user) | 110 | public function deleteAction(Request $request, User $user) |
100 | { | 111 | { |
@@ -135,8 +146,6 @@ class ManageController extends Controller | |||
135 | $form->handleRequest($request); | 146 | $form->handleRequest($request); |
136 | 147 | ||
137 | if ($form->isSubmitted() && $form->isValid()) { | 148 | if ($form->isSubmitted() && $form->isValid()) { |
138 | $this->get('logger')->info('searching users'); | ||
139 | |||
140 | $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'] : ''); |
141 | 150 | ||
142 | $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); | 151 | $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); |
@@ -161,7 +170,7 @@ class ManageController extends Controller | |||
161 | } | 170 | } |
162 | 171 | ||
163 | /** | 172 | /** |
164 | * Creates a form to delete a User entity. | 173 | * Create a form to delete a User entity. |
165 | * | 174 | * |
166 | * @param User $user The User entity | 175 | * @param User $user The User entity |
167 | * | 176 | * |