<?php
namespace App\Controller;
use App\Service\OngletService;
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\BinaryFileResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils, OngletService $ongletService): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
$errorMessage = null;
if ($error) {
switch ($error->getMessageKey()) {
case 'Email could not be found.':
$errorMessage = "Le compte est introuvable ou inactif.";
break;
case 'Invalid credentials.':
$errorMessage = "Mot de passe invalide.";
break;
}
//dump($error);
}
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => null,
'error' => $error,
'errorMessage' => $errorMessage,
'onglets' => $ongletService->getOnglets(),
]);
}
// /**
// * @Route("/assets/uploads/{entite}/{uid}/{nom}", name="uploads",
// * requirements={
// * "entite"="^[a-z0-9-_]+$",
// * "uid"="^[a-z0-9]+$",
// * "nom"="^[A-Za-z0-9-._]+$",
// * }
// * )
// */
// public function uploads($entite, $uid, $nom) {
//
// $user = $this->getUser();
//
// if (!$this->isGranted('ROLE_USER')
// && $entite !== 'actualite'
// && $entite !== 'contribution'
// && $entite !== 'slider'
// && $entite !== 'etablissement'
// && $entite !== 'formation'
// && $entite !== 'inscription_files'
// ) throw new AccessDeniedException();
//
// $fichier = $this->getParameter('kernel.project_dir') . '/public/assets/uploads/'.$entite.'/'.$uid.'/'.$nom;
//
// return new BinaryFileResponse($fichier);
// }
}