src/Controller/SecurityController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use App\Service\ManageurMailer;
  8. use App\Entity\User;
  9. use Symfony\Component\Security\Core\Security;
  10. class SecurityController extends AbstractController
  11. {
  12.     private $manageurMailer;
  13.     private $security;
  14.     public function __construct(ManageurMailer $manageurMailer,Security $security)
  15.     {
  16.         
  17.         $this->manageurMailer = $manageurMailer;
  18.         $this->security = $security;
  19.     }
  20.  
  21.     /**
  22.      * @Route("/connexion", name="app_login")
  23.      */
  24.     public function login(AuthenticationUtils $authenticationUtils): Response
  25.     {
  26.         
  27.        
  28.         $error = $authenticationUtils->getLastAuthenticationError();
  29.        
  30.         $lastUsername = $authenticationUtils->getLastUsername();
  31.         if ($this->isGranted('IS_AUTHENTICATED_FULLY') && $this->getUser() instanceof User) {
  32.             // L'utilisateur est authentifié avec succès
  33.             // $user = $this->security->getUser();
  34.           //  $this->mailService->sendLoginEmail($user->getLastname(), $user->getFirstname());
  35.             $this->manageurMailer->sendMailRegister("mazego.fr@gmail.com",$this->getUser()->getFirstname(), $this->getUser()->getLastname(), "Nouvelle connexion sur le site mazego.fr" );
  36.         }
  37.         return $this->render('security/loginTest.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
  38.     }
  39.     /**
  40.      * @Route("/deconnexion", name="app_logout")
  41.      */
  42.     public function logout()
  43.     {
  44.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  45.     }
  46. }