Symfony 检测第一个FOSFacebookBundle登录

Symfony 检测第一个FOSFacebookBundle登录,symfony,fosuserbundle,fosfacebookbundle,Symfony,Fosuserbundle,Fosfacebookbundle,我用FOSUserBundle成功地实现了FOSFacebookBundle。一切都很好 现在,我希望能够检测到用户与FOSFacebookBundle的第一个连接 我有一个FacebookAuthenticationSuccessHandler,每次Facebook身份验证成功时都会调用它,但我想声明一种“FirstFacebookAuthenticationSuccessHandler”,仅当用户还不存在时才调用。此处理程序的目标是能够向每个新用户发送欢迎电子邮件 对于经典注册,我只使用Re

我用FOSUserBundle成功地实现了FOSFacebookBundle。一切都很好

现在,我希望能够检测到用户与FOSFacebookBundle的第一个连接

我有一个FacebookAuthenticationSuccessHandler,每次Facebook身份验证成功时都会调用它,但我想声明一种“FirstFacebookAuthenticationSuccessHandler”,仅当用户还不存在时才调用。此处理程序的目标是能够向每个新用户发送欢迎电子邮件

对于经典注册,我只使用RegistrationSuccessListener


你知道我该怎么做吗?

在找到解决方案时回答我自己的问题

1/我创建(并注册)了一个名为NewFacebookUserListener的新事件侦听器:

...

/**
 * {@inheritDoc}
 */
 public static function getSubscribedEvents()
 {
      return array(
          MyCustomEvents::NEW_FACEBOOK_USER => 'onNewFacebookUser'
      );
 }

 public function onNewFacebookUser(UserEvent $event)
 {
      // we get the user
      $user = $event->getUser();

      // and now you can do what you wish
 }
2/在我的FacebookProvider(位于Security/User/Provider下)中,我添加了几行代码来发送此新事件:

$user->setFBData($fbdata);

// we send a "FB user created" event
$dispatcher = $this->container->get('event_dispatcher');
$dispatcher->dispatch(MyCustomEvents::NEW_FACEBOOK_USER, new UserEvent($user, $this->container->get('request')));
正如预期的那样,只有在创建新的Facebook用户时才会发送事件