<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route(path: '/login', name: 'provider_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if($this->getUser()) {
return $this->redirectToRoute('provider-profile');
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
if($error instanceof BadCredentialsException) {
$message= $error->getMessage();
if($message === 'Bad credentials.'){
$errorMessage= 'Aucun utilisateur ne correspond à ces identifiants.';
}else if($message === 'The presented password is invalid.'){
$errorMessage= 'Le mot de passe est incorrect.';
}
}
return $this->render('security/provider_login.html.twig', ['last_username' => $lastUsername, 'error' => $errorMessage ?? $error?->getMessage()]);
}
#[Route(path: '/logout', name: 'provider_logout')]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
#[Route(path: '/login_check', name: 'login_check')]
public function check()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}