<?php
namespace App\Controller\BaseSite\Auth;
use App\Repository\Website\Website\WebsiteRepository;
use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
//#[Route(host: "tlil.ir")]
class SecurityController extends AbstractController
{
#[Route(path: '/website-owner/login', name: 'shop_owner_login' )]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app_user_handler');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('@baseAuth/security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
#[Route(path: '/website-owner/user-handler', name: 'app_user_handler')]
public function userHandler(Security $security , WebsiteRepository $shopRepository): RedirectResponse
{
$user = $security->getUser();
if ($user->hasRole('ROLE_ADMIN')){
return $this->redirectToRoute('app_admin_dashboard');
}
if (count($shopRepository->findBy(['owner' => $user])) < 1){
return $this->redirectToRoute('app_base_site_user_setup_setup');
}
return $this->redirectToRoute('app_user_dashboard');
}
#[Route(path: '/website-owner/logout', name: 'shop_owner_logout')]
public function logout(): void
{
throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}