Bug into fosuserbundle when double click on confirmation link?

故事扮演 提交于 2019-12-06 00:52:48

问题


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 :

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

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

Thanks


回答1:


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

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

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


来源:https://stackoverflow.com/questions/15867960/bug-into-fosuserbundle-when-double-click-on-confirmation-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!