<?php
namespace App\Controller\Admin;
use App\Security\AdminFormAuthenticator;
use LogicException;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* @Route("/")
*/
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute(AdminFormAuthenticator::DASHBOARD_ROUTE);
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
// OPTIONAL parameters to customize the login form:
// the translation_domain to use (define this option only if you are
// rendering the login template in a regular Symfony controller; when
// rendering it from an EasyAdmin Dashboard this is automatically set to
// the same domain as the rest of the Dashboard)
'translation_domain' => 'admin',
// the title visible above the login form (define this option only if you are
// rendering the login template in a regular Symfony controller; when rendering
// it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
'page_title' => $this->get('twig')->getExtension(TranslationExtension::class)->trans('site.nume', [], 'admin'),
// the string used to generate the CSRF token. If you don't define
// this parameter, the login form won't include a CSRF token
'csrf_token_intention' => AdminFormAuthenticator::CSRF_TOKEN_KEY,
// the URL users are redirected to after the login (default: '/admin')
'target_path' => $this->generateUrl(AdminFormAuthenticator::DASHBOARD_ROUTE),
// the label displayed for the username form field (the |trans filter is applied to it)
'username_label' => 'page.login.email',
// the label displayed for the password form field (the |trans filter is applied to it)
'password_label' => 'page.login.parola',
// the label displayed for the Sign In form button (the |trans filter is applied to it)
'sign_in_label' => 'page.login.buton_login',
// the 'name' HTML attribute of the <input> used for the username field (default: '_username')
'username_parameter' => AdminFormAuthenticator::FIELD_USERNAME,
// the 'name' HTML attribute of the <input> used for the password field (default: '_password')
'password_parameter' => AdminFormAuthenticator::FIELD_PASSWORD,
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}