登录前Symfony 2 FOSFacebookBundle自定义重定向

ram*_*amo 4 symfony fosuserbundle

我在我的项目中使用FOSUserBundle和FOSFacebookBundle(适用于版本SF 2.0.x).另外,我实现并定制了FacebookProvider,如FOSFacebookBundle文档中所述.我想实现以下工作流程:1.)用户第一次访问我的门户2.)他点击Facebook登录按钮3.)现在我需要检查,如果这个用户,谁点击了Facebook登录-Button在我的门户网站上已经有了Facebook-Friends.4.)如果他有朋友,请使用预先填写的输入字段将他重定向到注册页面(包括来自Facebook的信息,如username,first_name,last_name等).5.)如果我的门户网站上没有Facebook好友,请将他重定向到另一个页面

我开始关注Webprofiler,这些事件被调用.我已经开始在这个页面上创建我自己的事件监听器:http://www.dobervich.com/2011/10/13/login-redirection-revisited/ 但是配置文件在"not not"列表中显示我的监听器调用侦听器":security.interactive_login SecurityListener :: onSecurityInteractiveLogin

有谁知道,我如何自定义此登录前检查并将用户重定向到页面?

很高兴能得到一些帮助.

谢谢你,拉莫

Kri*_*ith 5

您需要配置自定义身份验证成功处理程序.配置实现AuthenticationSuccessHandlerInterface的服务:

facebook_auth_success_handler:
    class: MyHandler
    public: false
    arguments:
        # your dependencies...
Run Code Online (Sandbox Code Playgroud)

然后将此处理程序添加到security.yml您的fos_facebook块下:

firewalls:
    foo:
        fos_facebook:
            success_handler: facebook_auth_success_handler
Run Code Online (Sandbox Code Playgroud)

处理程序本身应该如下所示:

public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
    $user = $token->getUser();
    $hasFriendsHereAlready = // your logic here
    if ($hasFriendsHereAlready) {
        $route = 'foo';
    } else {
        $route = 'bar';
    }
    return new RedirectResponse($this->router->generate($route));
}
Run Code Online (Sandbox Code Playgroud)