<?php
namespace App\Controller;
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 App\Service\ManageurMailer;
use App\Entity\User;
use Symfony\Component\Security\Core\Security;
class SecurityController extends AbstractController
{
private $manageurMailer;
private $security;
public function __construct(ManageurMailer $manageurMailer,Security $security)
{
$this->manageurMailer = $manageurMailer;
$this->security = $security;
}
/**
* @Route("/connexion", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
if ($this->isGranted('IS_AUTHENTICATED_FULLY') && $this->getUser() instanceof User) {
// L'utilisateur est authentifié avec succès
// $user = $this->security->getUser();
// $this->mailService->sendLoginEmail($user->getLastname(), $user->getFirstname());
$this->manageurMailer->sendMailRegister("mazego.fr@gmail.com",$this->getUser()->getFirstname(), $this->getUser()->getLastname(), "Nouvelle connexion sur le site mazego.fr" );
}
return $this->render('security/loginTest.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/deconnexion", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}