src/Controller/SecurityController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. class SecurityController extends AbstractController
  8. {
  9. /**
  10. * @Route("/", name="app_login")
  11. */
  12. public function login(AuthenticationUtils $authenticationUtils): Response
  13. {
  14. if ($this->getUser()) {
  15. $rolesToCheck = ['ROLE_ADMIN', 'ROLE_USER', 'ROLE_GUEST', 'ROLE_STADTRAUM', 'ROLE_SABER', 'ROLE_DBH'];
  16. if (array_filter($rolesToCheck, fn($role) => $this->isGranted($role))) {
  17. return $this->redirectToRoute('desk_booking');
  18. } elseif ($this->isGranted('ROLE_HAGEN')) {
  19. return $this->redirectToRoute('conference_room_booking');
  20. }
  21. }
  22. $error = $authenticationUtils->getLastAuthenticationError();
  23. $lastUsername = $authenticationUtils->getLastUsername();
  24. return $this->render('security/login.html.twig', [
  25. 'last_username' => $lastUsername,
  26. 'error' => $error
  27. ]);
  28. }
  29. /**
  30. * @Route("/logout", name="app_logout")
  31. */
  32. public function logout()
  33. {
  34. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  35. }
  36. }