| Current Path : /var/www/v3.cesa.co.za/src/UserBundle/Services/ |
| Current File : /var/www/v3.cesa.co.za/src/UserBundle/Services/LoginEntryPoint.php |
<?php
namespace App\UserBundle\Services;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface,
Symfony\Component\Security\Core\Exception\AuthenticationException,
Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\RedirectResponse,
Symfony\Component\Routing\RouterInterface;
/**
* When the user is not authenticated at all (i.e. when the security context has no token yet),
* the firewall's entry point will be called to start() the authentication process.
*/
class LoginEntryPoint implements AuthenticationEntryPointInterface
{
protected $router;
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
/*
* This method receives the current Request object and the exception by which the exception
* listener was triggered.
*
* The method should return a Response object
*/
public function start(Request $request, ?AuthenticationException $authException = null)
{
$session = $request->getSession();
// Check if this is an admin route
if (strpos($request->getPathInfo(), '/admin') === 0) {
// For admin routes, redirect to admin dashboard
// Sonata Admin Bundle will handle the authentication flow
$session->getFlashBag()->add('warning', 'You must be logged in to access the admin area');
return new RedirectResponse('/admin/dashboard');
}
// For regular routes, redirect to main login
$session->getFlashBag()->add('warning', 'You must be logged in to access that page');
return new RedirectResponse($this->router->generate('login'));
}
}