src/Controller/Auth/AuthController.php line 14

  1. <?php
  2. namespace App\Controller\Auth;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Bundle\SecurityBundle\Security;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class AuthController extends AbstractController
  9. {
  10.     #[Route('/'name'customer.login')]
  11.     public function customerLogin(AuthenticationUtils $authenticationUtils): Response
  12.     {
  13.         // get the login error if there is one
  14.         $error $authenticationUtils->getLastAuthenticationError();
  15.         // last username entered by the user
  16.         $lastUsername $authenticationUtils->getLastUsername();
  17.         return $this->render('login/frontend-login.html.twig', [
  18.             '_username' => $lastUsername,
  19.             'error' => $error
  20.         ]);
  21.     }
  22.     #[Route('/customer/logout'name'customer.logout')]
  23.     public function logout(AuthenticationUtils $authenticationUtils): Response
  24.     {
  25.         $error $authenticationUtils->getLastAuthenticationError();
  26.         $lastUsername $authenticationUtils->getLastUsername();
  27.         return $this->render('login/frontend-login.html.twig', [
  28.             'last_username' => $lastUsername,
  29.             'error' => $error,
  30.         ]);
  31.     }
  32.     #[Route('/admin'name'admin.login')]
  33.     public function index(AuthenticationUtils $authenticationUtils): Response
  34.     {
  35.         $error $authenticationUtils->getLastAuthenticationError();
  36.         $lastUsername $authenticationUtils->getLastUsername();
  37.         return $this->render('login/admin-login.html.twig', [
  38.             'last_username' => $lastUsername,
  39.             'error' => $error,
  40.         ]);
  41.     }
  42.     #[Route('/admin/logout'name'admin.logout')]
  43.     public function adminLogout(Security $security): Response
  44.     {
  45.         return $this->redirectToRoute('admin.login');
  46.     }
  47. }