Symfony 2 FOSFacebookBundle user redirection before login

I use FOSUserBundle and FOSFacebookBundle (for version SF 2.0.x) in my project. In addition, I implemented a custom FacebookProvider, as described in the FOSFacebookBundle documentation. I would like to get the following workflow: 1.) The user visits my portal for the first time 2.) He clicks the Facebook-Login-Button 3.) Now I need to check if this user has clicked the Facebook-Login-Button, I already have Facebook Friends on my portal. 4.) If he has friends, redirect him to the registration page (including information from Facebook, for example, username, username, filename, etc.) with pre-filled input fields. 5.) If he does not have Facebook friends on my portal, redirect him to another page

I started looking at Webprofiler what events are causing. I started creating my own event listener, as described on this page: http://www.dobervich.com/2011/10/13/login-redirection-revisited/ , but the profile shows me my listener in the list of "non-invoked listeners" : security.interactive_login SecurityListener :: onSecurityInteractiveLogin

Does anyone know how I can configure this pre-login check and redirect the user to the page?

It would be great to help you with this.

Thanks Ramo

+4
source share
1 answer

You need to set up your own authentication success handler. Configure a service that implements AuthenticationSuccessHandlerInterface :

facebook_auth_success_handler: class: MyHandler public: false arguments: # your dependencies... 

Then add this handler to security.yml in the fos_facebook block:

 firewalls: foo: fos_facebook: success_handler: facebook_auth_success_handler 

The handler itself should look something like this:

 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)); } 
+5
source

Source: https://habr.com/ru/post/1388824/


All Articles