我想根据用户的角色在登录后自定义重定向.
仅供参考:我用 symfony 2.8
我创建这个类:
<?php
namespace Users\UsersBundle\Redirection;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
class AfterLoginRedirection implements AuthenticationSuccessHandlerInterface
{
protected $router;
protected $security;
/**
* AfterLoginRedirection constructor.
* @param Router $router
* @param Security $security
*/
public function __construct(Router $router, Security $security)
{
$this->router = $router;
$this->security = $security;
}
/**
* @param Request $request
* @param TokenInterface $token
* @return RedirectResponse
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
$response …Run Code Online (Sandbox Code Playgroud)