双击确认链接时错误进入fosuserbundle? [英] Bug into fosuserbundle when double click on confirmation link?

查看:132
本文介绍了双击确认链接时错误进入fosuserbundle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用fosuserbundle,今天我激活了确认注册链接. 效果很好,但是如果用户再次单击电子邮件中的确认链接,则会收到该错误:

I just begin to use fosuserbundle, today I activate the confirmation register link. It works great, but if the user click a second time on the confirmation link in the email, he get that error :

具有确认令牌"3hiqollkisg0s4ck4w8g0gw4soc0wwoo8ko084o4ww4ssss8o4"的用户不存在 找不到404-NotFoundHttpException

The user with confirmation token "3hiqollkisg0s4ck4w8g0gw4soc0wwoo8ko084o4ww4sss8o4" does not exist 404 Not Found - NotFoundHttpException

我认为此错误应由捆绑包处理,不是吗?

I think this error should be handle by the bundle, no ?

谢谢

推荐答案

以下是重写操作的代码.基本上只是复制了实际FOS动作的一部分并进行了修改.

Here's the code for overriding the action. Basically just copied part of the actual FOS action and modded.

在用户捆绑包的controller文件夹中创建一个RegistrationController.php文件,并将覆盖的RegistrationController类放在其中.

Create a RegistrationController.php file in your user bundle's controller folder and put the overriding RegistrationController class in there.

假设您的用户捆绑包是Acme \ UserBundle:

Assuming your user bundle is Acme\UserBundle:

<?php

// Acme\UserBundle\RegistrationController.php

namespace Acme\UserBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class RegistrationController extends BaseController
{
    /**
     * Receive the confirmation token from user email provider, login the user
     */
    public function confirmAction(Request $request, $token)
    {
        $userManager = $this->container->get('fos_user.user_manager');

        $user = $userManager->findUserByConfirmationToken($token);

        if (null === $user) {

            /* ************************************
            *
            * User with token not found. Do whatever you want here
            *
            * e.g. redirect to login: 
            *
            * return new RedirectResponse($this->container->get('router')->generate('fos_user_security_login'));
            *
            **************************************/ 

        }
        else{
            // Token found. Letting the FOSUserBundle's action handle the confirmation 
            return parent::confirmAction($request, $token);
        }
    }
}

这篇关于双击确认链接时错误进入fosuserbundle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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