findAll(); return $this->render('user/list.html.twig', [ 'usemenu' => true, 'usesidebar' => true, 'title' => 'Liste des Utilisateurs', 'routesubmit' => 'app_admin_user_submit', 'routeupdate' => 'app_admin_user_update', 'users' => $users, ]); } #[Route('/admin/user/submit', name: 'app_admin_user_submit')] public function submit(Request $request, UserPasswordHasherInterface $passwordHasher, EntityManagerInterface $em): Response { $user = new User(); $form = $this->createForm(UserType::class, $user, ['mode' => 'submit']); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $user = $form->getData(); $hashedPassword = $passwordHasher->hashPassword( $user, $user->getPassword() ); $user->setPassword($hashedPassword); $em->persist($user); $em->flush(); return $this->redirectToRoute('app_admin_user'); } return $this->render('user/edit.html.twig', [ 'usemenu' => true, 'usesidebar' => true, 'title' => 'Création Utilisateur', 'routecancel' => 'app_admin_user', 'routedelete' => 'app_admin_user_delete', 'mode' => 'submit', 'form' => $form, ]); } #[Route('/admin/user/update/{id}', name: 'app_admin_user_update')] public function update(int $id, Request $request, UserPasswordHasherInterface $passwordHasher, EntityManagerInterface $em): Response { $user = $em->getRepository(User::class)->find($id); if (!$user) { return $this->redirectToRoute('app_admin_user'); } $form = $this->createForm(UserType::class, $user, ['mode' => 'update']); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $user = $form->getData(); $hashedPassword = $passwordHasher->hashPassword( $user, $user->getPassword() ); $user->setPassword($hashedPassword); $em->persist($user); $em->flush(); return $this->redirectToRoute('app_admin_user'); } return $this->render('user/edit.html.twig', [ 'usemenu' => true, 'usesidebar' => true, 'title' => 'Création Utilisateur', 'routecancel' => 'app_admin_user', 'routedelete' => 'app_admin_user_delete', 'mode' => 'update', 'form' => $form, ]); } #[Route('/admin/user/delete', name: 'app_admin_user_delete')] public function delete(): Response { return $this->redirectToRoute('app_admin_user'); } #[Route('/user', name: 'app_user_profil')] public function profil(): Response { return $this->redirectToRoute('app_home'); } }