Php 覆盖FOSUserBundle(Symfony2)中的登录控制器

Php 覆盖FOSUserBundle(Symfony2)中的登录控制器,php,symfony,fosuserbundle,Php,Symfony,Fosuserbundle,我目前正在从WordPress迁移到Symfony2网站 我在Symfony2上导入了我所有的WP用户,但现在我正在寻找一种方法,在用户尝试登录时进行额外检查(通常检查用户是否从WP导入并检查其旧密码) 在用户身份验证中添加一些检查的最佳方法是什么?(登录检查fosuserbundle) 我只是试图覆盖SecurityController,但它不起作用,因为这里似乎没有登录 谢谢你的帮助 编辑:我需要在登录过程中添加支票,而不是在登录之后。在登录过程中,如果用户来自WordPress,我想检查他

我目前正在从WordPress迁移到Symfony2网站

我在Symfony2上导入了我所有的WP用户,但现在我正在寻找一种方法,在用户尝试登录时进行额外检查(通常检查用户是否从WP导入并检查其旧密码)

在用户身份验证中添加一些检查的最佳方法是什么?(登录检查fosuserbundle)

我只是试图覆盖SecurityController,但它不起作用,因为这里似乎没有登录

谢谢你的帮助


编辑:我需要在登录过程中添加支票,而不是在登录之后。在登录过程中,如果用户来自WordPress,我想检查他提供的密码是否与他以前的WordPress密码(也存储在数据库中)相同。

我最终找到了一个解决方案,但不确定这是最好的方法

我在登录失败时添加了一个侦听器,并检查它是否是WordPress的用户

现在我正在寻找一个解决方案来处理“记住我”复选框,因为用户是一个通过编程进行身份验证的用户。代码如下:

public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
    $username = $request->request->get('_username');
    $password = $request->request->get('_password');

    $user = $this->doctrine->getRepository('AppBundle:User')->findOneByUsername($username);

    if ($user instanceof User && $user->getFromWordpress() == true) {

        //The class use by WordPress to check / encode passwords
        $hasher = new PasswordHash(8, TRUE);    

        //User provide the right password
        if ($hasher->CheckPassword($password, $user->getWordpressPassword())){

            //Programmatically authenticate the user
            $token = new UsernamePasswordToken($user, $user->getPassword(), "main", $user->getRoles());
            $this->tokenStorage->setToken($token);
            $event = new InteractiveLoginEvent($request, $token);
            $this->eventDispacher->dispatch("security.interactive_login", $event);

            //Set the password with the Symfony2 encoder
            $encoder = $this->encoderFactory->getEncoder($user);
            $password = $encoder->encodePassword($password, $user->getSalt());
            $user->setPassword($password);
            $user->setFromWordpress(false);
            $this->doctrine->getManager()->persist($user);
            $this->doctrine->getManager()->flush();

            //Finnaly send login ok response
            return $this->onAuthenticationSuccess($request, $token);
        }
    }   

    //Login failed code ...
    //.....
}

查看:类AuthenticationSuccessListener{/***@param AuthenticationSuccessEvent$event*/AuthenticationSuccessResponse上的公共函数(AuthenticationSuccessEvent$event)或者更好的检查:I的可能副本不会覆盖控制器,而是为
fos\u user.security.implicit\u login
事件创建一个事件侦听器。请参阅您是否已经知道该用户是从WP导入的?您是否将其存储为属性或其他与该用户链接的内容?