duanfuxing2417 2015-05-07 07:55
浏览 42

如何覆盖确认注册重定向和FOSUserBundle检查启用了电子邮件确认的位置?

1) FOSUserBundle registration redirects to confirmedAction bydefault

        if (null === $response = $event->getResponse()) {
            $url = $this->generateUrl('fos_user_registration_confirmed');
            $response = new RedirectResponse($url);
        }

        $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

        return $response;

I want to override this behaviour as I am calling registerAction using REST. I want to return confirmation message instead of redirecting.

FilterUserResponseEvent do not allow to set response, there is no "setResponse" method.

2) FOSUserBundle's EmailConfirmationListener also redirects to checkEmail action

    $url = $this->router->generate('fos_user_registration_check_email');
    $event->setResponse(new RedirectResponse($url));

I want to override this behavious as well. I could do this by creating my EmailConfirmationListener service with same id "fos_user.listener.email_confirmation" and by doing this

$response = new Response($this->translator->trans('registration.check_email', array(
                '%email%' => $user->getEmail()), 'FOSUserBundle'));
        $event->setResponse($response);

But the problem is now below configuration is not working. It always sends confirmation email regardless of below configuration.

fos_user
   registration 
       confirmation
           enabled : false

I couldn't see any code in EmailConfirmationListerner which checks whether this configuration is enabled or not. Where is it checked, why overriding Listener stops configuration working ?

  • 写回答

1条回答 默认 最新

  • douchun6108 2015-09-18 14:34
    关注

    For your first question, setting your own redirect response should be done on FOSUserEvents::REGISTRATION_SUCCESS rather than FOSUserEvents::REGISTRATION_COMPLETED. This is precisely why the code you pasted from the bundle is checking whether a response is set before creating its own RedirectResponse.

    For your second question, the behaviour of the configuration setting is to register the confirmation listener or to skip registering in the bundle. If you register your own listener, you have to control the registration of your own listener on your side.

    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP