3 namespace Wallabag\UserBundle\Controller
;
5 use FOS\UserBundle\Event\UserEvent
;
6 use FOS\UserBundle\FOSUserEvents
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
9 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method
;
10 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
11 use Wallabag\UserBundle\Entity\User
;
12 use Wallabag\CoreBundle\Entity\Config
;
17 class ManageController
extends Controller
20 * Lists all User entities.
22 * @Route("/", name="user_index")
25 public function indexAction()
27 $em = $this->getDoctrine()->getManager();
29 $users = $em->getRepository('WallabagUserBundle:User')->findAll();
31 return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
37 * Creates a new User entity.
39 * @Route("/new", name="user_new")
40 * @Method({"GET", "POST"})
42 public function newAction(Request
$request)
44 $userManager = $this->container
->get('fos_user.user_manager');
46 $user = $userManager->createUser();
47 // enable created user by default
48 $user->setEnabled(true);
50 $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [
51 'validation_groups' => ['Profile'],
53 $form->handleRequest($request);
55 if ($form->isSubmitted() && $form->isValid()) {
56 $userManager->updateUser($user);
58 // dispatch a created event so the associated config will be created
59 $event = new UserEvent($user, $request);
60 $this->get('event_dispatcher')->dispatch(FOSUserEvents
::USER_CREATED
, $event);
62 $this->get('session')->getFlashBag()->add(
64 $this->get('translator')->trans('flashes.user.notice.added', ['%username%' => $user->getUsername()])
67 return $this->redirectToRoute('user_edit', array('id' => $user->getId()));
70 return $this->render('WallabagUserBundle:Manage:new.html.twig', array(
72 'form' => $form->createView(),
77 * Displays a form to edit an existing User entity.
79 * @Route("/{id}/edit", name="user_edit")
80 * @Method({"GET", "POST"})
82 public function editAction(Request
$request, User
$user)
84 $deleteForm = $this->createDeleteForm($user);
85 $editForm = $this->createForm('Wallabag\UserBundle\Form\UserType', $user);
86 $editForm->handleRequest($request);
88 if ($editForm->isSubmitted() && $editForm->isValid()) {
89 $em = $this->getDoctrine()->getManager();
93 $this->get('session')->getFlashBag()->add(
95 $this->get('translator')->trans('flashes.user.notice.updated', ['%username%' => $user->getUsername()])
98 return $this->redirectToRoute('user_edit', array('id' => $user->getId()));
101 return $this->render('WallabagUserBundle:Manage:edit.html.twig', array(
103 'edit_form' => $editForm->createView(),
104 'delete_form' => $deleteForm->createView(),
105 'twofactor_auth' => $this->getParameter('twofactor_auth'),
110 * Deletes a User entity.
112 * @Route("/{id}", name="user_delete")
115 public function deleteAction(Request
$request, User
$user)
117 $form = $this->createDeleteForm($user);
118 $form->handleRequest($request);
120 if ($form->isSubmitted() && $form->isValid()) {
121 $this->get('session')->getFlashBag()->add(
123 $this->get('translator')->trans('flashes.user.notice.deleted', ['%username%' => $user->getUsername()])
126 $em = $this->getDoctrine()->getManager();
131 return $this->redirectToRoute('user_index');
135 * Creates a form to delete a User entity.
137 * @param User $user The User entity
139 * @return \Symfony\Component\Form\Form The form
141 private function createDeleteForm(User
$user)
143 return $this->createFormBuilder()
144 ->setAction($this->generateUrl('user_delete', array('id' => $user->getId())))
145 ->setMethod('DELETE')