<?php
/**
* This file is part of Synapse.
*
* Copyright (C) 2020-2021 Daniel Ménard
*
* For copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Controller;
use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* Contrôleur de sécurité.
*
* Fournit les routes /login et /logout.
*
* @author Daniel Ménard <daniel.menard.35@gmail.com>
*/
class SecurityController extends AbstractController
{
/**
* Permet à l'utilisateur de se connecter.
*
* @Route("/login", name="login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// Redirige l'utilisateur s'il est déjà connecté (-> non, pas pratique si on veut changer de user)
// if ($this->getUser()) {
// return $this->redirectToRoute('app_home');
// }
// Récupère le dernier message d'erreur de connexion (s'il existe)
$error = $authenticationUtils->getLastAuthenticationError();
// Récupère le login que l'utilisateur a saisit lors de la dernière tentative
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('pages/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* Permet à l'utilisateur de se déconnecter.
*
* @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.');
}
}