FOSUserBundle:密码重置后的成功目标 [英] FOSUserBundle: Success target after password reset

查看:83
本文介绍了FOSUserBundle:密码重置后的成功目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户使用FOSUserBundle的密码重置来重置密码后,默认情况下,他将被重定向到FOSUserProfile. 我想重定向到其他路线. 这可能吗?如果可以,怎么办?

After the user did reset his password using the password reset of FOSUserBundle, by default he is redirected to the FOSUserProfile. I want to redirect to a different route. Is this possible and if yes, how?

推荐答案

可以通过创建重置用户来完成:

It can be done by creating a resetting subscriber:

namespace Acme\UserBundle\EventListener;

use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Listener responsible to change the redirection at the end of the password resetting
 */
class PasswordResettingListener implements EventSubscriberInterface {
    private $router;

    public function __construct(UrlGeneratorInterface $router) {
        $this->router = $router;
    }

    public static function getSubscribedEvents() {
        return [
            FOSUserEvents::RESETTING_RESET_SUCCESS => 'onPasswordResettingSuccess',
        ];
    }

    public function onPasswordResettingSuccess(FormEvent $event) {
        $url = $this->router->generate('homepage');
        $event->setResponse(new RedirectResponse($url));
    }
}

然后使用kernel.event_subscriber标签将其注册为服务:

And then registering it as a service with kernel.event_subscriber tag:

# src/Acme/UserBundle/Resources/config/services.yml
services:
    acme_user.password_resetting:
        class: Acme\UserBundle\EventListener\PasswordResettingListener
        arguments: [ @router ]
        tags:
            - { name: kernel.event_subscriber }

这篇关于FOSUserBundle:密码重置后的成功目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆