src/Controller/Adherent/Registration/UserController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Adherent\Registration;
  3. use App\Entity\ContactEmail;
  4. use App\Entity\User;
  5. use App\Form\Adherent\Registration\UserPasswordType;
  6. use App\Form\Adherent\Registration\UserType;
  7. use App\Security\AdherentLoginAuthenticator;
  8. use App\Service\Registration\Session;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;
  14. #[Route(path'/inscription'name'registration_user')]
  15. class UserController extends AbstractRegistrationController
  16. {
  17.     protected static int $step 1;
  18.     public function __construct(protected Session $registrationSessionEntityManagerInterface $em, private readonly AuthenticatorManager $authenticatorManager)
  19.     {
  20.         parent::__construct($registrationSession$em);
  21.     }
  22.     #[Route(path'/nouvel-espace'name'')]
  23.     public function user(Request $requestUserPasswordHasherInterface $passwordHasherAdherentLoginAuthenticator $authenticator)
  24.     {
  25.         if ($this->getUser()) {
  26.             $this->registrationSession->setStep(static::$step 1);
  27.             return $this->redirectToRoute('registration_family');
  28.         }
  29.         $user = new User();
  30.         $user->setIsTemporary(true);
  31.         $user->setPassword($passwordHasher->hashPassword($useruniqid(''true)));
  32.         $form $this->createForm(UserType::class, $user)->handleRequest($request);
  33.         if ($form->isSubmitted() && $form->isValid()) {
  34.             $contactEmail = (new ContactEmail())
  35.                 ->setEmail($user->getEmail());
  36.             $user->getPerson()->setFirstEmail($contactEmail);
  37.             $this->em->persist($user);
  38.             $this->em->flush();
  39.             $type $form->get('type')->getData();
  40.             if ($type === 'self') {
  41.                 $this->registrationSession->setPerson($user->getPerson());
  42.             }
  43.             $this->registrationSession->setRegistrationType($type);
  44.             $this->authenticatorManager->authenticateUser($user$authenticator$request);
  45.             return $this->redirectToRoute('registration_family');
  46.         }
  47.         return $this->render('adherent/registration/user.html.twig', ['form' => $form->createView()]);
  48.     }
  49.     #[Route(path'/utilisateur'name'_validation')]
  50.     public function validation(Request $requestAdherentLoginAuthenticator $authenticator)
  51.     {
  52.         $step 8;
  53.         if ($step $this->registrationSession->getStep()) {
  54.             return $this->redirectToRoute('registration_user');
  55.         }
  56.         $season $this->registrationSession->getSeason();
  57.         $person $this->registrationSession->getPerson();
  58.         $user $this->getUser();
  59.         $data = ['email' => $user->getEmail()];
  60.         $form $this->createForm(UserPasswordType::class, $data, ['temporary_user' => $user->isIsTemporary()])
  61.             ->handleRequest($request);
  62.         if ($form->isSubmitted() && $form->isValid()) {
  63.             if ($form->has('plainPassword')) {
  64.                 $plainPassword $form->get('plainPassword')->getData();
  65.                 $user->setPlainPassword($plainPassword);
  66.             }
  67.             $this->registrationSession->setStep($step 1);
  68.             $this->em->flush();
  69.             return $this->redirectToRoute('registration_finalize');
  70.         }
  71.         return $this->render('adherent/registration/user_validation.html.twig', [
  72.             'form'   => $form->createView(),
  73.             'step'   => $step,
  74.             'season' => $season,
  75.             'person' => $person,
  76.             'email'  => $user->getEmail(),
  77.         ]);
  78.     }
  79. }