src/Controller/SecurityController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\OngletService;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  9. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. class SecurityController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/login", name="app_login")
  15.      */
  16.     public function login(AuthenticationUtils $authenticationUtilsOngletService $ongletService): Response
  17.     {
  18.         // get the login error if there is one
  19.         $error $authenticationUtils->getLastAuthenticationError();
  20.         $errorMessage null;
  21.         if ($error) {
  22.           switch ($error->getMessageKey()) {
  23.             case 'Email could not be found.':
  24.               $errorMessage "Le compte est introuvable ou inactif.";
  25.               break;
  26.             case 'Invalid credentials.':
  27.               $errorMessage "Mot de passe invalide.";
  28.               break;
  29.           }
  30.           //dump($error);
  31.         }
  32.         // last username entered by the user
  33.         $lastUsername $authenticationUtils->getLastUsername();
  34.         return $this->render('security/login.html.twig', [
  35.           'last_username' => null,
  36.           'error' => $error,
  37.           'errorMessage' => $errorMessage,
  38.           'onglets' => $ongletService->getOnglets(),
  39.         ]);
  40.     }
  41. //    /**
  42. //     * @Route("/assets/uploads/{entite}/{uid}/{nom}", name="uploads",
  43. //     *   requirements={
  44. //     *     "entite"="^[a-z0-9-_]+$",
  45. //     *     "uid"="^[a-z0-9]+$",
  46. //     *     "nom"="^[A-Za-z0-9-._]+$",
  47. //     *   }
  48. //     * )
  49. //     */
  50. //    public function uploads($entite, $uid, $nom) {
  51. //
  52. //        $user = $this->getUser();
  53. //
  54. //        if (!$this->isGranted('ROLE_USER')
  55. //            && $entite !== 'actualite'
  56. //            && $entite !== 'contribution'
  57. //            && $entite !== 'slider'
  58. //            && $entite !== 'etablissement'
  59. //            && $entite !== 'formation'
  60. //            && $entite !== 'inscription_files'
  61. //        ) throw new AccessDeniedException();
  62. //
  63. //        $fichier = $this->getParameter('kernel.project_dir') . '/public/assets/uploads/'.$entite.'/'.$uid.'/'.$nom;
  64. //
  65. //        return new BinaryFileResponse($fichier);
  66. //    }
  67. }