src/Controller/RegistrationController.php line 24
<?phpnamespace App\Controller;use App\Entity\Coach;use App\Entity\Offre;use App\Entity\User;use App\Form\RegistrationFormType;use App\Security\LoginFormAuthenticator;use App\Service\EmailService;use Doctrine\ORM\EntityManagerInterface;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;use Symfony\Component\Validator\Validator\ValidatorInterface;class RegistrationController extends AbstractController{#[Route('/register', name: 'app_register')]public function register(EntityManagerInterface $em,EmailService $email,Request $request, UserPasswordHasherInterface $userPasswordHasher, UserAuthenticatorInterface $userAuthenticator, LoginFormAuthenticator $authenticator, EntityManagerInterface $entityManager,ValidatorInterface $validator): Response{$user = new User();// OFFRE GRATUIT 1$offre = $em->getRepository(Offre::class)->find(1);$coach = $em->getRepository(Coach::class)->find(2);$form = $this->createForm(RegistrationFormType::class, $user);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {// encode the plain password$user->setPassword($userPasswordHasher->hashPassword($user,$form->get('password')->getData()));$user->setRoles(['ROLE_USER_NO_VALIDE']);$user->setOffre($offre);$entityManager->persist($user);$entityManager->flush();// do anything else you need here, like send an email$email->sendWelcomeMessage($user);$this->addFlash('success','1');return $this->redirectToRoute('app_login', ['error' => false]);}return $this->render('registration/register.html.twig', ['registrationForm' => $form,]);}}