Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
proc
/
212
/
root
/
proc
/
self
/
root
/
proc
/
212
/
root
/
proc
/
70528
/
cwd
/
src
/
Controller
/
//proc/212/root/proc/self/root/proc/212/root/proc/70528/cwd/src/Controller/SecurityController.php
<?php namespace App\Controller; use App\Entity\User; use App\Form\UserType; use App\Form\UserEditType; use App\Repository\UserRepository; use App\Security\UserAuthenticator; use App\Repository\CommandRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface; /** * @Route("/user") */ class SecurityController extends AbstractController { /** * @Route("/login", name="app_login") */ public function login(AuthenticationUtils $authenticationUtils): Response { // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError(); // last username entered by the user $lastUsername = $authenticationUtils->getLastUsername(); return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); } /** * @Route("/register", name="app_register") */ public function register(Request $request, ManagerRegistry $doctrine, UserPasswordHasherInterface $hasher, UserAuthenticator $formAuthenticator, UserAuthenticatorInterface $authenticator) { $user = new User(); $form = $this->createForm(UserType::class, $user); $form->handleRequest($request); $user->setRoles(["ROLE_USER"]); if ($form->isSubmitted() && $form->isValid()) { $plainPassword = $user->getPassword(); $password = $hasher->hashPassword($user, $plainPassword); $user->setPassword($password); try { $em = $doctrine->getManager(); $em->persist($user); $em->flush(); } catch (UniqueConstraintViolationException $e) { $this->addFlash("danger", "Adresse email déja utilisée !"); return $this->redirectToRoute("app_login"); } $this->addFlash("success", "Compte utilisateur crée, vous êtes connecté !"); return $authenticator->authenticateUser( $user, $formAuthenticator, $request ); } return $this->render("security/register.html.twig", [ "form" => $form->createView() ]); } /** * @Route("/logout", name="app_logout") */ public function logout(): void { throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); } /** * @Route("/", name="app_user_account") */ public function userAccount() { $user = $this->getUser(); if ($user == null) return $this->redirectToRoute("app_login"); if (in_array("ROLE_ADMIN", $this->getUser()->getRoles())) { return $this->redirectToRoute("back_homepage"); } return $this->render("front/user/account.html.twig", [ "user" => $user ]); } /** * @Route("/edit", name="app_user_account_edit") */ public function editUserAccount(UserRepository $userRepository, ManagerRegistry $doctrine, Request $request, UserPasswordHasherInterface $hasher) { $userId = $this->getUser()->getId(); $user = $userRepository->find($userId); $form = $this->createForm(UserEditType::class, $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $doctrine->getManager(); $em->persist($user); $em->flush(); $this->addFlash("success", "Votre informations ont été modifiés !"); return $this->redirectToRoute("app_user_account"); } return $this->render("front/user/edit.html.twig", [ "form" => $form->createView() ]); } /** * @Route("/commande/{id}/detail", name="app_user_command_read") */ public function readUserCommand($id, CommandRepository $commandRepository) { $command = $commandRepository->find($id); return $this->render("front/user/command_read.html.twig", [ "command" => $command ]); } }