src/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\AddAdministrator;
  4. use Flasher\Prime\FlasherInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/login", name="app_login")
  13.      */
  14.     public function login(AuthenticationUtils $authenticationUtilsFlasherInterface $flasherAddAdministrator $addAdmin): Response
  15.     {
  16.          $resp $addAdmin->createAdminUser();
  17.          if ($this->getUser()) {
  18.              $toastr $flasher->create('toastr');
  19.              $toastr->addSuccess('Bon retour parmit nous!');
  20.              return $this->redirectToRoute('app_home');
  21.          }
  22.         // get the login error if there is one
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         // last username entered by the user
  25.         $lastUsername $authenticationUtils->getLastUsername();
  26.         if($error) {
  27.             $toastr $flasher->create('toastr');
  28.             $toastr->addError('VĂ©rifiez vos paramètres de connexion !');
  29.         }
  30.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  31.     }
  32.     /**
  33.      * @Route("/logout", name="app_logout")
  34.      */
  35.     public function logout(): void
  36.     {
  37.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  38.     }
  39. }