<?php
namespace App\Controller;
use App\Service\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class SecurityController extends AbstractController
{
private $utils;
private $translator;
private $em;
private $repository;
private $requestStack;
private $tokenStorage;
private $twig;
private $router;
private $flash;
public function __construct(TranslatorInterface $translator, TokenStorageInterface $tokenStorage, RequestStack $requestStack, EntityManagerInterface $em, Environment $twig, RouterInterface $router, FlashBagInterface $flash)
{
$this->translator = $translator;
$this->em = $em;
$this->twig = $twig;
$this->tokenStorage = $tokenStorage;
$this->router = $router;
$this->flash = $flash;
$this->requestStack = $requestStack;
$this->utils = new Utils($translator, $tokenStorage, $requestStack, $em, $twig, $router, $flash);
}
/**
* @Route("/", name="app_login")
*/
public function index(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app_dashboard');
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/forgot_password", name="app_forgotpassword")
*/
public function forgotPassword(): Response
{
return $this->render('security/forgot_password.html.twig', []);
}
/**
* @Security("is_granted('ROLE_USER')")
* @Route("/switchlanguage/{locale}", name="app_switchlanguage")
* @param $locale
* @return RedirectResponse|Response
*/
public function switchLanguage(Request $request, $locale = 'en') {
$referer = $request->headers->get('referer');
$request->attributes->set('_locale', null);
$this->requestStack->getSession()->set('_locale', $locale);
return $this->redirect($referer);
}
/**
* @Route("/logout", name="app_logout", methods={"GET"})
*/
public function logout(): void
{
}
/**
* @Security("is_granted('ROLE_USER')")
* @Route("/release_notes", name="app_release_notes")
*/
public function releaseNotes(): Response
{
return $this->render('release_notes.html.twig', [
'title' => $this->translator->trans('release_notes', array(), 'fields'),
'sub_title' => $this->translator->trans('release_notes', array(), 'fields')
]);
}
}