<?php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Trace;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends BaseController
{
/**
* @Route("/login", name="login")
*/
public function login(
Request $request,
AuthenticationUtils $authenticationUtils,
AuthorizationCheckerInterface $securityContext,
) {
$session = $request->getSession();
$session->set('alertstock', 1);
if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
// Create trace object on connection
$trace = new Trace(
"Connexion au système",
"Connexion",
$request->getUri(),
"globale",
$this->utilisateur->getId(),
$this->utilisateur,
$this->magasin
);
$this->manager->persist($trace);
$this->manager->flush();
return $this->redirectToRoute('homepage');
}
return $this->render('default/login.html.twig', [
'last_username' => $authenticationUtils->getLastUsername(),
'error' => $authenticationUtils->getLastAuthenticationError(),
]);
}
/**
* @Route("/logout", name="logout")
*/
public function logoutAction(Request $request)
{
//Create trace object on connexion:
$trace = new Trace(
"Deconnexion du système",
"Connexion",
$request->getUri(),
"globale",
$this->utilisateur->getId(),
$this->utilisateur,
$this->magasin
);
$this->manager->persist($trace);
$this->manager->flush();
}
}