Symfony2,FOSUser,重置密码后不登录用户 [英] Symfony2, FOSUser, don't login user after reset password

查看:59
本文介绍了Symfony2,FOSUser,重置密码后不登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on resetting password system with FosUser, and I don't know how can I remove the auto-login after user changes his password ?

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

Thanks for help, I don't want to override, I change directly FOS files.

推荐答案

正确的方法:)

Symfony中的编译器传递允许您操纵其他服务.在这种情况下,您要覆盖fos_user.listener.authentication以使用您的自定义订阅服务器,而不是FOSUserBundle FOS\UserBundle\EventListener\AuthenticationListener提供的订阅服务器.您可以将提供的内容扩展为仅订阅注册事件,而不订阅重置密码事件:

Compiler Passes in Symfony allow you to manipulate other services. In this case you want to override fos_user.listener.authentication to use your custom subscriber instead of the one provided with FOSUserBundle FOS\UserBundle\EventListener\AuthenticationListener. You can just extends the provided one to subscribe only to the registration events and NOT to the resetting password event:

<?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'
        );
    }

}

要这样做,只需定义一个Compiler Pass:

To do so just define a Compiler Pass like this:

<?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');
    }

}

然后在包定义中注册编译器遍历:

And then register your compiler pass in your bundle definition:

<?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());
    }

}

就是这样!

这里有几本书要读: 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

这篇关于Symfony2,FOSUser,重置密码后不登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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