createForm(RegistrationFormType::class, $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var string $plainPassword */ $plainPassword = $form->get('plainPassword')->getData(); $user->setRoles(['ROLE_INTERN']); // encode the plain password $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); $entityManager->persist($user); $entityManager->flush(); // do anything else you need here, like send an email return $security->login($user, 'form_login', 'intern'); } return $this->render('registration/register.html.twig', [ 'registrationForm' => $form, ]); } #[Route('/employee', name: '_employee')] public function registerEmployee(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager): Response { $user = new Employee(); $form = $this->createForm(RegistrationFormType::class, $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var string $plainPassword */ $plainPassword = $form->get('plainPassword')->getData(); $user->setRoles(['ROLE_EMPLOYEE']); // encode the plain password $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); $entityManager->persist($user); $entityManager->flush(); // do anything else you need here, like send an email return $security->login($user, 'form_login', 'employee'); } return $this->render('registration/register.html.twig', [ 'registrationForm' => $form, ]); } }