用户使用FOSUserBundle的密码重设重置密码后,默认情况下会重定向到FOSUserProfile。 我想重定向到另一条路线。 这是可能的,如果可以,怎么样?
答案 0 :(得分:41)
可以通过创建重置订户来完成:
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 }
答案 1 :(得分:21)
如果您没有使用FOS用户个人资料视图,则有一种丑陋但简单的方法:
添加app/config/routing.yml
:
fos_user_profile_show:
path: /yourpath