Bug into fosuserbundle when double click on confirmation link?

邮差的信 提交于 2019-12-04 06:12:44

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