在我的symfony2项目中,我正在使用FOSFacebookBundle,它工作得很好。如果该FB用户已经存在于数据库中,则该用户已登录,如果该用户尚未注册,则该用户将被添加到该数据库中,并从fb检索数据。
到目前为止还不错,但现在我想将用户重定向到配置文件编辑页面,如果用户在此过程中注册,否则将重定向到主页。我如何实现这一点?我只知道用户是否存在于提供者中,我是否应该将一些信息注册到提供者中的会话中,然后创建一些侦听器来读取会话并进行重定向?
欢迎任何提示:)
发布于 2013-05-28 06:55:34
您需要配置自定义身份验证成功处理程序和身份验证失败处理程序。配置实现AuthenticationSuccessHandlerInterface:和AuthenticationFailureHandlerInterface的服务
facebook_auth_success_handler:
class: MyHandler
public: false
arguments:
# your dependencies...然后将此处理程序添加到fos_facebook块下的security.yml中:
firewalls:
foo:
fos_facebook:
success_handler: facebook_auth_success_handler发布于 2013-05-28 06:55:37
当您使用FOSUserBundle时(根据问题上的标记),您可以连接到控制器并在事件REGISTRATION_SUCCESS上重定向(在创建用户时)。
在您的情况下,它应该如下所示:
// src/Acme/UserBundle/EventListener/RegistrationSuccessListener.php
class RegistrationSuccessListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess'
);
}
public function onRegistrationSuccess(GetResponseUserEvent $event)
{
$url = $this->router->generate('profile_edit_page');
$event->setResponse(new RedirectResponse($url));
}
}和你的service.yml
services:
acme_user.registration.success:
class: Acme\UserBundle\EventListener\RegistrationSuccessListener
arguments: [@router]
tags:
- { name: kernel.event_subscriber }https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/controller_events.md
https://stackoverflow.com/questions/16781175
复制相似问题