gpt4 book ai didi

symfony - FOSUserBundle:密码重置后的成功目标

转载 作者:行者123 更新时间:2023-12-02 08:25:25 24 4
gpt4 key购买 nike

用户使用 FOSUserBundle 的密码重置重置密码后,默认情况下他会被重定向到 FOSUserProfile。我想重定向到不同的路线。这可能吗?如果可以,如何实现?

最佳答案

可以通过创建重置订阅者来完成:

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 标记将其注册为服务:

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

关于symfony - FOSUserBundle:密码重置后的成功目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15878341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com