src/Controller/Security/SecurityController.php line 20
<?phpnamespace App\Controller\Security;use App\Entity\User;use App\Form\RegistrationFormType;use App\Repository\UserRepository;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\AuthenticationUtils;class SecurityController extends AbstractController{#[Route(path: '/login', name: 'app_login')]public function login(AuthenticationUtils $authenticationUtils,UserRepository $userRepository): Response{//test has userif ($this->getUser()) {$user = $this->getUser();if(in_array('ROLE_ADMIN',$user->getRoles())){return $this->redirectToRoute('app_admin_home');}else{return $this->redirectToRoute('app_pos_home');}}// 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,'users' => $userRepository->findAll()]);}#[Route('/register', name: 'app_register')]public function register(Request $request,UserPasswordHasherInterface $userPasswordHasher,EntityManagerInterface $entityManager): Response{//test has userif ($this->getUser()) {$user = $this->getUser();if(in_array('ROLE_ADMIN',$user->getRoles())){return $this->redirectToRoute('app_admin_home');}else{return $this->redirectToRoute('app_pos_home');}}$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('plainPassword')->getData()));$entityManager->persist($user);$entityManager->flush();// do anything else you need here, like send an emailreturn $this->redirectToRoute('app_login');}return $this->render('security/register.html.twig', ['registrationForm' => $form->createView(),]);}#[Route(path: '/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.');}}