Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug into fosuserbundle when double click on confirmation link?

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

like image 512
user2178964 Avatar asked Apr 07 '13 21:04

user2178964


1 Answers

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);
        }
    }
}
like image 180
Prynz Avatar answered Sep 18 '22 00:09

Prynz