src/Controller/SecurityController.php line 14

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\Core\Exception\BadCredentialsException;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10.     #[Route(path'/login'name'provider_login')]
  11.     public function login(AuthenticationUtils $authenticationUtils): Response
  12.     {
  13.         if($this->getUser()) {
  14.             return $this->redirectToRoute('provider-profile');
  15.         }
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         $lastUsername $authenticationUtils->getLastUsername();
  18.         if($error instanceof BadCredentialsException) {
  19.             $message$error->getMessage();
  20.             if($message === 'Bad credentials.'){
  21.                 $errorMessage'Aucun utilisateur ne correspond à ces identifiants.';
  22.             }else if($message === 'The presented password is invalid.'){
  23.                 $errorMessage'Le mot de passe est incorrect.';
  24.             }
  25.         }
  26.         return $this->render('security/provider_login.html.twig', ['last_username' => $lastUsername'error' => $errorMessage ?? $error?->getMessage()]);
  27.     }
  28.     #[Route(path'/logout'name'provider_logout')]
  29.     public function logout(): void
  30.     {
  31.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  32.     }
  33.     #[Route(path'/login_check'name'login_check')]
  34.     public function check()
  35.     {
  36.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  37.     }
  38. }