Symfony2,FOSUser,重置密码后不登录用户

Clé*_*aud 2 symfony fosuserbundle

我正在使用FosUser重置密码系统,我不知道如何在用户更改密码后删除自动登录?

感谢您的帮助,我不想覆盖,我直接更改FOS文件.

ggi*_*eda 5

正确的方法 :)

Symfony中的编译器通行证允许您操纵其他服务.在这种情况下,您希望覆盖fos_user.listener.authentication以使用自定义订户而不是FOSUserBundle提供的订户FOS\UserBundle\EventListener\AuthenticationListener.您可以只扩展提供的一个只订阅注册事件而不是重置密码事件:

<?php
// src/YourCompany/YourBundle/EventListener/AuthenticationListener.php

namespace YourCompany\YourBundle\EventListener;

use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\EventListener\AuthenticationListener as FOSAuthenticationListener;

class AuthenticationListener extends FOSAuthenticationListener
{

    public static function getSubscribedEvents()
    {
        return array(
            FOSUserEvents::REGISTRATION_COMPLETED => 'authenticate',
            FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate'
        );
    }

}
Run Code Online (Sandbox Code Playgroud)

为此,只需像这样定义一个编译器通行证:

<?php
// src/YourCompany/YourBundle/DependencyInjection/Compiler/FOSUserOverridePass.php

namespace YourCompany\YourBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class FOSUserOverridePass implements CompilerPassInterface
{

    public function process(ContainerBuilder $container)
    {
        $container->getDefinition('fos_user.listener.authentication')->setClass('YourCompany\YourBundle\EventListener\AuthenticationListener');
    }

}
Run Code Online (Sandbox Code Playgroud)

然后在bundle定义中注册编译器传递:

<?php
// src/YourCompany/YourBundle/YourCompanyYourBundle.php

namespace YourCompany\YourBundle;

use YourCompany\YourBundle\Compiler\FOSUserOverridePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class YourCompanyYourBundle extends Bundle
{

    public function build(ContainerBuilder $container)
    {
        parent::build($container);
        $container->addCompilerPass(new FOSUserOverridePass());
    }

}
Run Code Online (Sandbox Code Playgroud)

而已!


以下是阅读内容:http://symfony.com/doc/current/cookbook/service_container/compiler_passes.html

您要覆盖的服务:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/config/listeners.xml

原始类:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/EventListener/AuthenticationListener.php