<?php
namespace App\Controller\Website\Auth;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
class LoginController extends AbstractController
{
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
/**
* @Route("/{_locale}/login", name="login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
$request = $this->requestStack->getCurrentRequest();
$locale = $request->getLocale();
return new RedirectResponse('/' . $locale . '/mediabank');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
// $lastUsername = "";
$errorMessage = "";
if ($error) {
$errorMessage = "You have entered an incorrect email or password. If you happen to forget it, please contact us at infо@modern.expo";
}
return $this->render('auth/login.html.twig', ['last_username' => $lastUsername, 'error' => $errorMessage]);
//return $this->render('auth/login.html.twig', []);
}
/**
* @Route("/logout", name="logout")
*/
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}