src/Controller/Admin/Auth/AuthController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin\Auth;
  3. use App\Model\User\Entity\User\Role;
  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. class AuthController extends AbstractController
  9. {
  10.    #[Route('/login'name'admin_login')]
  11.     public function login(AuthenticationUtils $authenticationUtils): Response
  12.     {
  13. //        if ($this->getUser()) {
  14. //            return $this->redirectToRoute('admin');
  15. //        }
  16.        if ($this->getUser() && $this->isGranted(Role::ADMIN)) {
  17.            return $this->redirectToRoute('admin');
  18.        }
  19.        // get the login error if there is one
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         // last username entered by the user
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         return $this->render('admin/auth/login.html.twig',
  24.             ['last_username' => $lastUsername'error' => $error]
  25.         );
  26.     }
  27.     #[Route('/logout'name'app_logout')]
  28.     public function logout()
  29.     {
  30.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  31.     }
  32. }