src/Controller/BaseSite/Auth/SecurityController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller\BaseSite\Auth;
  3. use App\Repository\Website\Website\WebsiteRepository;
  4. use LogicException;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Core\Security;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. //#[Route(host: "tlil.ir")]
  12. class SecurityController extends AbstractController
  13. {
  14.     #[Route(path'/website-owner/login'name'shop_owner_login' )]
  15.     public function login(AuthenticationUtils $authenticationUtils): Response
  16.     {
  17.          if ($this->getUser()) {
  18.              return $this->redirectToRoute('app_user_handler');
  19.          }
  20.         // get the login error if there is one
  21.         $error $authenticationUtils->getLastAuthenticationError();
  22.         // last username entered by the user
  23.         $lastUsername $authenticationUtils->getLastUsername();
  24.         return $this->render('@baseAuth/security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  25.     }
  26.     #[Route(path'/website-owner/user-handler'name'app_user_handler')]
  27.     public function userHandler(Security $security WebsiteRepository $shopRepository): RedirectResponse
  28.     {
  29.         $user $security->getUser();
  30.         if ($user->hasRole('ROLE_ADMIN')){
  31.             return $this->redirectToRoute('app_admin_dashboard');
  32.         }
  33.         if (count($shopRepository->findBy(['owner' => $user])) < 1){
  34.             return  $this->redirectToRoute('app_base_site_user_setup_setup');
  35.         }
  36.         return $this->redirectToRoute('app_user_dashboard');
  37.     }
  38.     #[Route(path'/website-owner/logout'name'shop_owner_logout')]
  39.     public function logout(): void
  40.     {
  41.         throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  42.     }
  43. }