src/Controller/SecurityController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Article;
  4. use App\Entity\User;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/", name="app_login")
  14.      */
  15.     public function login(AuthenticationUtils $authenticationUtils): Response
  16.     {
  17.         if ($user $this->getUser()) {
  18.             if ($user->hasRoles(User::ROLE_ADMIN)) {
  19.                 return $this->redirectToRoute('users_index');
  20.             }
  21.             return $this->redirectToRoute('dashboard_articles');
  22.         }
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         $lastUsername $authenticationUtils->getLastUsername();
  25.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  26.     }
  27.     /**
  28.      * @Route("/logout", name="app_logout")
  29.      */
  30.     public function logout()
  31.     {
  32.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  33.     }
  34. }