src/Controller/SecurityController.php line 21
<?phpnamespace App\Controller;use App\Entity\User;use App\Form\RegistrationFormType;use App\Security\LoginFormAuthenticator;use Doctrine\ORM\EntityManagerInterface;use Exception;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\RedirectResponse;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\AuthenticationUtils;use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;class SecurityController extends AbstractController{public function login(AuthenticationUtils $authenticationUtils): Response{// if ($this->getUser()) {// return $this->redirectToRoute('target_path');// }// 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]);}public function logout(): void{throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');}public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, UserAuthenticatorInterface $userAuthenticator, LoginFormAuthenticator $authenticator, EntityManagerInterface $entityManager): Response{$user = new User();$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()));$entityManager->persist($user);$entityManager->flush();// do anything else you need here, like send an emailreturn $userAuthenticator->authenticateUser($user,$authenticator,$request);}return $this->render('registration/register.html.twig', ['registrationForm' => $form->createView(),]);}}