src/Controller/User/LoginController.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Controller\User;
  3. use App\Service\MobileDetectService;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. class LoginController extends AbstractController
  12. {
  13.     private $urlGenerator;
  14.     private $mobileDetectService;
  15.     function __construct(UrlGeneratorInterface $urlGeneratorMobileDetectService $mobileDetectService)
  16.     {
  17.         $this->urlGenerator  $urlGenerator;
  18.         $this->mobileDetectService $mobileDetectService;
  19.     }
  20.     /**
  21.      * @Route("/", name="check_user")
  22.      */
  23.     public function check()
  24.     {
  25.         if($this->getUser()){
  26.             if($this->isGranted('ROLE_ADMIN')){ 
  27.                 return $this->redirectToRoute('admin_google_professional_save_locations');
  28.             }else{
  29.                 if($this->mobileDetectService->isMobile()){
  30.                     return $this->redirectToRoute('professional_mobile_home');
  31.                 }else{
  32.                     return $this->redirectToRoute('professional_dashboard');
  33.                 }
  34.             }
  35.         }else{
  36.             return $this->redirectToRoute('app_login');
  37.         }
  38.     }
  39.     /**
  40.      * @Route("/login", name="app_login")
  41.      */
  42.     public function login(AuthenticationUtils $authenticationUtilsRequest $request): Response
  43.     {
  44.         // if($request->getScheme() === "http"){
  45.         //     $secureLogin = "https:" . $this->generateUrl("app_login", [], UrlGeneratorInterface::NETWORK_PATH);
  46.         //     dump($request->getScheme());
  47.         //     // return $this->redirect($secureLogin);
  48.         // }
  49.         
  50.         if($this->getUser() !== null){
  51.             
  52.             $roles $this->getUser()->getRoles(); 
  53.             if(in_array("ROLE_ADMIN"$roles)){
  54.                 return $this->redirectToRoute("home");
  55.             }else{
  56.                 return $this->redirectToRoute("professional_dashboard");
  57.             }
  58.         }
  59.         // get the login error if there is one
  60.         $error $authenticationUtils->getLastAuthenticationError();
  61.         // last username entered by the user
  62.         $lastUsername $authenticationUtils->getLastUsername();
  63.         return $this->render('user/security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  64.     }
  65.     /**
  66.      * @Route("/logout", name="app_logout")
  67.      */
  68.     public function logout()
  69.     { }
  70.     /**
  71.      * @Route("/not-found", name="not_found")
  72.      */
  73.     public function notFound(){
  74.         return new Response($this->renderView("layouts/not-found.html.twig"), 404);
  75.         // return ;
  76.     }
  77. }