Bug into fosuserbundle when double click on confirmation link?
Asked Answered
S

1

6

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

Shechem answered 7/4, 2013 at 21:19 Comment(2)
Having this same issue and looking for a solution. There's no scope for dumb users who double click everything!!Payroll
It should be handle, but it's not. The same thing when double click reseting pasword link, after password request interval expires. The only thing that worked for me is to 'override ' routing to fosuser:confirm action so it routes to action i wrote. Basicly overriding part of fos user bundle controler. In my action I check confirmation hash, if exists I forward to fosuserbundle:registration:confirm. If not - I echo some message. I can provide some code later.Rabush
D
6

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);
        }
    }
}
Deventer answered 6/9, 2013 at 7:46 Comment(1)
You need to make FOSUserBundle a parent of your application's bundle, see hereHeptad

© 2022 - 2024 — McMap. All rights reserved.