php两个登录角色,php – Symfony2 / FOSUserBundle – 根据角色登录后重定向

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

仅供参考:我使用的是symfony 2.8

我创建这个类:

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 = new RedirectResponse($this->router->generate('_homepage_admin'));

} else {

$referer_url = $request->headers->get('referer');

$response = new RedirectResponse($referer_url);

}

return $response;

}

}

我创建这个服务:

services:

redirect.after.login:

class: Users\UsersBundle\Redirection\AfterLoginRedirection

arguments: [@router]

我修改了防火墙

firewalls:

main:

pattern: ^/

form_login:

login_path: fos_user_security_login

check_path: fos_user_security_check

provider: fos_userbundle

csrf_provider: form.csrf_provider

success_handler: redirect.after.login

logout:

path: /users/logout

target: /

anonymous: true

我收到了这个错误:

Catchable Fatal Error: Argument 1 passed to

Users\UsersBundle\Redirection\AfterLoginRedirection::__construct()

must be an instance of Users\UsersBundle\Redirection\Router, instance

of Symfony\Bundle\FrameworkBundle\Routing\Router given, called in

C:\wamp\www\eCommerce\app\cache\dev\appDevDebugProjectContainer.php on

line 2060 and defined

我错过了什么?任何线索或建议?

谢谢.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值