src/Controller/SecurityController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use App\Entity\Trace;
  6. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends BaseController
  9. {
  10.     /**
  11.      * @Route("/login", name="login")
  12.      */
  13.     public function login(
  14.         Request $request,
  15.         AuthenticationUtils $authenticationUtils,
  16.         AuthorizationCheckerInterface $securityContext,
  17.     ) {
  18.         $session $request->getSession();
  19.         $session->set('alertstock'1);
  20.         
  21.         if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
  22.             // Create trace object on connection
  23.             $trace = new Trace(
  24.                 "Connexion au système",
  25.                 "Connexion",
  26.                 $request->getUri(),
  27.                 "globale",
  28.                 $this->utilisateur->getId(),
  29.                 $this->utilisateur,
  30.                 $this->magasin
  31.             );
  32.             
  33.             $this->manager->persist($trace);
  34.             $this->manager->flush();
  35.         
  36.             return $this->redirectToRoute('homepage');
  37.         }
  38.         return $this->render('default/login.html.twig', [
  39.             'last_username' => $authenticationUtils->getLastUsername(),
  40.             'error' => $authenticationUtils->getLastAuthenticationError(),
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/logout", name="logout")
  45.      */
  46.     public function logoutAction(Request $request)
  47.     {
  48.         //Create trace object on connexion:
  49.         $trace = new Trace(
  50.             "Deconnexion du système",
  51.             "Connexion",
  52.             $request->getUri(),
  53.             "globale",
  54.             $this->utilisateur->getId(),
  55.             $this->utilisateur,
  56.             $this->magasin
  57.         );
  58.         $this->manager->persist($trace);
  59.         $this->manager->flush();
  60.     }
  61. }