webroot/src/Controller/SecurityController.php

48 lines
1.8 KiB
PHP

<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Bundle\SecurityBundle\Security;
use App\Controller\WebrootController;
class SecurityController extends WebrootController
{
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// 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', array_merge(
$this->getControllerVariables(), [
'login_title' => $this->trans("login.title",domain:"security"),
'login_button' => $this->trans("login.button",domain:"security"),
'login_username' => $this->trans("login.username",domain:"security"),
'login_password' => $this->trans("login.password",domain:"security"),
'login_remember_me' => $this->trans("login.remember_me",domain:"security"),
'login_forgotten_password' => $this->trans("login.forgotten_password",domain:"security"),
'last_username' => $lastUsername,
'error' => $error,
]));
}
#[Route('/logout',name:'app_logout')]
public function logout(Security $security): Response
{
if ($this->getUser()) {
$response = $security->logout(false);
} else {
$response = $this->redirect("Login");
}
return $response;
}
}