src/Controller/SecurityController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use App\Repository\UserRepository;
  10. class SecurityController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/login", name="app_login")
  14.      */
  15.     public function login(AuthenticationUtils $authenticationUtilsSession $session): Response
  16.     {
  17.         $utilisateur $this->getUser();
  18.         //vérification des droits.
  19.         if($utilisateur && in_array('ROLE_USER'$utilisateur->getRoles())){
  20.             return $this->redirectToRoute('app_switch');
  21.         } 
  22.         // get the login error if there is one
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         // last username entered by the user
  25.         $lastUsername $authenticationUtils->getLastUsername();
  26.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  27.     }
  28.     
  29.     /**
  30.      * @Route("/logout", name="app_logout")
  31.      */
  32.     public function logout()
  33.     {
  34.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  35.     }
  36.     
  37.     /**
  38.      * @Route("/users", name="app_users")
  39.      */
  40.     public function users(UserRepository $userRepository) : Response
  41.     {        
  42.     return $this->render('users.html.twig', [
  43.             'title' => 'Utilisateurs',
  44.             'users' => $userRepository->findAll(),
  45.         ]);  
  46.     }
  47. }