小编Let*_*cks的帖子

Symfony2/FOSUserBundle - 根据角色登录后重定向

我想根据用户的角色在登录后自定义重定向.

仅供参考:我用 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)

php symfony fosuserbundle

5
推荐指数
1
解决办法
1715
查看次数

标签 统计

fosuserbundle ×1

php ×1

symfony ×1