src/Controller/SecurityController.php line 28

  1. <?php
  2. namespace App\Controller;
  3. use http\Client\Request;
  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 App\Repository\UserRepository;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. class SecurityController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/login", name="app_login")
  14.      */
  15.     public function login(AuthenticationUtils $authenticationUtilsUserRepository $userRepositoryRequestStack $requestStack): Response
  16.     {
  17.         $error $authenticationUtils->getLastAuthenticationError();
  18.         $userEmail $authenticationUtils->getLastUsername();
  19.         $session $requestStack->getSession();
  20.         if ($userEmail) {
  21.             $user $userRepository->findOneBy(['email' => $userEmail]);
  22.             if ($user && $user->getDefaultLanguage()) {
  23.                 $session->set('selected_language'$user->getDefaultLanguage());
  24.             }
  25.         }
  26.         return $this->render('security/login.html.twig', [
  27.             'last_username' => $userEmail,
  28.             'error' => $error,
  29.         ]);
  30.     }
  31.     /**
  32.      * @Route("/logout", name="app_logout")
  33.      */
  34.     public function logout()
  35.     {
  36.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  37.     }
  38. }