<?php
namespace App\Controller;
use App\Entity\Customer\Customer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class CustomerSecurityController extends AbstractController
{
private $doctrine;
public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}
/**
* @Route("/connexion", name="customer_login")
*/
public function login(AuthenticationUtils $authenticationUtils, Request $request): Response
{
$targePath = "";
if($request->query->get('back')){
$targePath = $request->query->get('back');
$settings = $request->query->all();
$link = '?';
foreach ($settings as $setting => $value) {
if($setting != 'back'){
$targePath .= $link.$setting.'='.$value;
$link = '&';
}
}
}
// dd($this);
// $customerEntityManager = $this->doctrine->getManager('customer');
if ($this->getUser()) {
return $this->redirectToRoute('account');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('mon-compte/login.html.twig', ['last_username' => $lastUsername, 'error' => $error, 'targetPath' => $targePath]);
}
/**
* @Route("/deconnexion", name="customer_logout")
*/
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}