src/Controller/SecurityController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Contracts\Translation\TranslatorInterface;
  4. use Symfony\Component\Translation\LocaleSwitcher;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Twig\Environment;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use App\Entity\Category;
  13. class SecurityController extends BaseCommonController
  14. {
  15. // after login success get the user profile
  16.     // #[Route(path: '/api/login', name: 'api_login',methods:['POST'])]
  17.     // public function login(){
  18.     //     $user = $this->getUser();
  19.     //     return $this->json([
  20.     //         'username' => $user->getUsername(),
  21.     //         'roles' => $user->getRoles(),
  22.     //         ]);
  23.     //     }
  24.     #[Route(path'/login'name'app_login')]
  25.     public function login(AuthenticationUtils $authenticationUtils,ManagerRegistry $doctrine,Request $request,
  26.     TranslatorInterface $translator,LocaleSwitcher $localeSwitcher ): Response
  27.     {
  28.         if ($request->query->has('_locale')) {
  29.             $locale =  $request->getSession()->get('_locale');
  30.             if($locale !=null){
  31.                 $localeSwitcher->setLocale($locale);
  32.                 $translator->setLocale($locale);    
  33.                 $request->getSession()->set('_locale',$locale);
  34.             }
  35.         }
  36.         // if ($this->getUser()) {
  37.         //     return $this->redirectToRoute('target_path');
  38.         // }
  39.         // get the login error if there is one
  40.         $error $authenticationUtils->getLastAuthenticationError();
  41.         // last username entered by the user
  42.         $lastUsername $authenticationUtils->getLastUsername();
  43.         // $categories = $this->categories($doctrine);      
  44.         // if (!$authenticationUtils->getIsVerified()){
  45.         //     var_dump("must verify to continue ");
  46.             
  47.         // }
  48.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  49.     }
  50.     
  51. // autre methode de login 
  52.     // #[Route(path: '/api/login', name: 'api_login',methods:['POST'])]
  53.     // public function login(){
  54.     //     $user = $this->getUser();
  55.     //     return $this->json([
  56.     //         'username' => $user->getUsername(),
  57.     //         'roles' => $user->getRoles(),
  58.     //         ]);
  59.     
  60.     #[Route(path'/aboutus'name'app_aboutus')]
  61.     public function aboutus(Environment $twig
  62.     ,TranslatorInterface $translator,LocaleSwitcher $localeSwitcher,Request $request ): Response
  63.     {
  64.         if ($request->query->has('_locale')) {
  65.             $locale =  $request->getSession()->get('_locale');
  66.             if($locale !=null){
  67.                 $localeSwitcher->setLocale($locale);
  68.                 $translator->setLocale($locale);    
  69.             }
  70.         }
  71.         return $this->render('profile/aboutus.html.twig');
  72.     }
  73.     
  74.     #[Route(path'/logout'name'app_logout')]
  75.     public function logout(): void
  76.     {
  77.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  78.     }
  79.             
  80.     }
  81. // }