简体   繁体   English

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

[英]How to override confirm registration redirect and where email confirmation enabled is checked by FOSUserBundle?

1) FOSUserBundle registration redirects to confirmedAction bydefault 1)FOSUserBundle注册默认重定向到ConfirmedAction

        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. 我想使用REST调用registerAction时覆盖此行为。 I want to return confirmation message instead of redirecting. 我想返回确认消息,而不是重定向。

FilterUserResponseEvent do not allow to set response, there is no "setResponse" method. FilterUserResponseEvent不允许设置响应,没有“ setResponse”方法。

2) FOSUserBundle's EmailConfirmationListener also redirects to checkEmail action 2)FOSUserBundle的EmailConfirmationListener也重定向到checkEmail操作

    $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 我可以通过创建具有相同ID“ fos_user.listener.email_confirmation”的EmailConfirmationListener服务并执行此操作

$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. 我在EmailConfirmationListerner中看不到任何代码来检查是否启用了此配置。 Where is it checked, why overriding Listener stops configuration working ? 在哪里检查,为什么覆盖侦听器停止配置工作?

For your first question, setting your own redirect response should be done on FOSUserEvents::REGISTRATION_SUCCESS rather than FOSUserEvents::REGISTRATION_COMPLETED . 对于第一个问题,应该在FOSUserEvents::REGISTRATION_SUCCESS而不是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. 这就是为什么您从分发包粘贴的代码在创建自己的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. 如果注册自己的侦听器,则必须在自己的侧面控制自己的侦听器的注册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM