<?php
namespace App\Controller\AppBundle\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Log;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/", name="login")
* @param AuthenticationUtils $authUtils
* @return \Symfony\Component\HttpFoundation\Response
*/
public function loginAction(AuthenticationUtils $authUtils, Request $request, EntityManagerInterface $em)
{
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->redirectToRoute('dashboard');
}
$error = $authUtils->getLastAuthenticationError();
$hasError = ($error != null);
$lastUser = $authUtils->getLastUsername();
if ($hasError) {
Log::log($em, $request, 'Login attempt', null, null, [
'email' => $lastUser
]);
}
Log::log($em, $request, 'Page load', null, 'Login');
return $this->render('@App/pages/security/login.html.twig', [
'hasError' => $hasError,
'lastUser' => $lastUser
]);
}
}