src/Controller/SecurityController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\TblSociete;
  4. use App\Entity\User;
  5. use App\Form\UserFormType;
  6. use App\Repository\TblSocieteRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  13. /**
  14.  * @Route("/")
  15.  */
  16. class SecurityController extends AbstractController
  17. {
  18.     /**
  19.      * @Route("/login", name="app_login")
  20.      */
  21.     public function login(AuthenticationUtils $authenticationUtils  ): Response
  22.     {
  23.         if ($this->getUser()) {
  24.             return $this->redirectToRoute('home');
  25.         }
  26.         // get the login error if there is one
  27.         $error $authenticationUtils->getLastAuthenticationError();
  28.         // last username entered by the user
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         $logoRepo =  $this->getDoctrine()->getRepository(TblSociete::class)->find(1);
  31.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error,'logoSociete' => $logoRepo ]);
  32.     }
  33.     /**
  34.      * @ParamConverter("user", options={"mapping": {"id": "userId"}})
  35.      * @Route("/profile/{id}", name="profile")
  36.      */
  37.     public function profile(Request $requestUser $user)
  38.     {
  39.         $entityManager $this->getDoctrine()->getManager();
  40.         $form $this->createForm(UserFormType::class, $user);
  41.         $form->handleRequest($request);
  42.         if($form->isSubmitted() && $form->isValid())
  43.         {
  44.             $entityManager->flush();
  45.             $this->addFlash(
  46.                 'success',
  47.                 'user.alert.update'
  48.             );
  49.             return $this->redirectToRoute('profile', ['id' => $user->getUserId()], Response::HTTP_SEE_OTHER);
  50.         }
  51.         return $this->render("security/profile.html.twig", [
  52.             "form" => $form->createView(),
  53.             "retour_button" => 'Retour',
  54.         ]);
  55.     }
  56.         /**
  57.      * @Route("/create-user", name="user_create_todelete", methods={"GET","POST"})
  58.      */
  59.     public function new(Request $request): Response
  60.     {
  61.         $user = new User();
  62.         $form $this->createForm(UserFormType::class, $user);
  63.         $form->handleRequest($request);
  64.         if ($form->isSubmitted() && $form->isValid()) {
  65.             $entityManager $this->getDoctrine()->getManager();
  66.             $entityManager->persist($user);
  67.             $entityManager->flush();
  68.             return $this->redirectToRoute('product_admin_index');
  69.         }
  70.         return $this->render('security/_form.html.twig', [
  71.             'form' => $form->createView(),
  72.         ]);
  73.     }
  74.     /**
  75.      * @Route("/logout", name="app_logout")
  76.      */
  77.     public function logout()
  78.     {
  79.     }
  80. }