在用户使用 FOSUserBundle 的密码重置重置他的密码后,默认情况下他被重定向到 FOSUserProfile。我想重定向到不同的路线。这可能吗?如果可以,怎么做?
问问题
15985 次
2 回答
44
可以通过创建一个重置订阅者来完成:
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 }
于 2013-04-08T13:06:43.523 回答
23
如果您不使用 FOS 用户配置文件视图,有一个丑陋但简单的方法:
添加你的app/config/routing.yml
:
fos_user_profile_show:
path: /yourpath
于 2014-09-24T15:47:19.457 回答