src/Controller/SecurityController.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\Utils;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Routing\RouterInterface;
  14. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  15. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. use Twig\Environment;
  18. class SecurityController extends AbstractController
  19. {
  20.     private $utils;
  21.     private $translator;
  22.     private $em;
  23.     private $repository;
  24.     private $requestStack;
  25.     private $tokenStorage;
  26.     private $twig;
  27.     private $router;
  28.     private $flash;
  29.     public function __construct(TranslatorInterface $translatorTokenStorageInterface $tokenStorageRequestStack $requestStackEntityManagerInterface $emEnvironment $twigRouterInterface $routerFlashBagInterface $flash)
  30.     {
  31.         $this->translator $translator;
  32.         $this->em $em;
  33.         $this->twig $twig;
  34.         $this->tokenStorage $tokenStorage;
  35.         $this->router $router;
  36.         $this->flash $flash;
  37.         $this->requestStack $requestStack;
  38.         $this->utils = new Utils($translator$tokenStorage$requestStack$em$twig$router$flash);
  39.     }
  40.     /**
  41.      * @Route("/", name="app_login")
  42.      */
  43.     public function index(AuthenticationUtils $authenticationUtils): Response
  44.     {
  45.         if ($this->getUser()) {
  46.             return $this->redirectToRoute('app_dashboard');
  47.         }
  48.         $error $authenticationUtils->getLastAuthenticationError();
  49.         $lastUsername $authenticationUtils->getLastUsername();
  50.         return $this->render('security/login.html.twig', [
  51.             'last_username' => $lastUsername,
  52.             'error' => $error,
  53.         ]);
  54.     }
  55.     /**
  56.      * @Route("/forgot_password", name="app_forgotpassword")
  57.      */
  58.     public function forgotPassword(): Response
  59.     {
  60.         return $this->render('security/forgot_password.html.twig', []);
  61.     }
  62.     /**
  63.      * @Security("is_granted('ROLE_USER')")
  64.      * @Route("/switchlanguage/{locale}", name="app_switchlanguage")
  65.      * @param $locale
  66.      * @return RedirectResponse|Response
  67.      */
  68.     public function switchLanguage(Request $request$locale 'en') {
  69.         $referer $request->headers->get('referer');
  70.         $request->attributes->set('_locale'null);
  71.         $this->requestStack->getSession()->set('_locale'$locale);
  72.         return $this->redirect($referer);
  73.     }
  74.     /**
  75.      * @Route("/logout", name="app_logout", methods={"GET"})
  76.      */
  77.     public function logout(): void
  78.     {
  79.     }
  80.     /**
  81.      * @Security("is_granted('ROLE_USER')")
  82.      * @Route("/release_notes", name="app_release_notes")
  83.      */
  84.     public function releaseNotes(): Response
  85.     {
  86.         return $this->render('release_notes.html.twig', [
  87.             'title' => $this->translator->trans('release_notes', array(), 'fields'),
  88.             'sub_title' => $this->translator->trans('release_notes', array(), 'fields')
  89.         ]);
  90.     }
  91. }