<?php
namespace App\Controller;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Translation\LocaleSwitcher;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Category;
class SecurityController extends BaseCommonController
{
// after login success get the user profile
// #[Route(path: '/api/login', name: 'api_login',methods:['POST'])]
// public function login(){
// $user = $this->getUser();
// return $this->json([
// 'username' => $user->getUsername(),
// 'roles' => $user->getRoles(),
// ]);
// }
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils,ManagerRegistry $doctrine,Request $request,
TranslatorInterface $translator,LocaleSwitcher $localeSwitcher ): Response
{
if ($request->query->has('_locale')) {
$locale = $request->getSession()->get('_locale');
if($locale !=null){
$localeSwitcher->setLocale($locale);
$translator->setLocale($locale);
$request->getSession()->set('_locale',$locale);
}
}
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
// $categories = $this->categories($doctrine);
// if (!$authenticationUtils->getIsVerified()){
// var_dump("must verify to continue ");
// }
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
// autre methode de login
// #[Route(path: '/api/login', name: 'api_login',methods:['POST'])]
// public function login(){
// $user = $this->getUser();
// return $this->json([
// 'username' => $user->getUsername(),
// 'roles' => $user->getRoles(),
// ]);
#[Route(path: '/aboutus', name: 'app_aboutus')]
public function aboutus(Environment $twig
,TranslatorInterface $translator,LocaleSwitcher $localeSwitcher,Request $request ): Response
{
if ($request->query->has('_locale')) {
$locale = $request->getSession()->get('_locale');
if($locale !=null){
$localeSwitcher->setLocale($locale);
$translator->setLocale($locale);
}
}
return $this->render('profile/aboutus.html.twig');
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}
// }