FriendsOfSymfony / FOSUserBundle

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.

Home Page:https://symfony.com/doc/master/bundles/FOSUserBundle/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EmailConfirmationListener not redirecting to /register/check-email page

xeon826 opened this issue · comments

Symfony FOSUserBundle versions:
friendsofsymfony/user-bundle v2.1.2

Description of the problem including expected versus actual behavior:
I bought a third party php script here, I haven't tampered with much of anything aside from the config.yml where I set registration: confirmation: enabled: true and the email to use for sending. After the user inputs their credentials, they're taken to a login page without any sort of alert or indication that an email has been sent.

I input (manually) /register/check-email and it indicates that the user has been sent an email but for some reason, the website does not automatically redirect to this page of its own accord. I feel like there might be an option missing in either config.yml or services.yml but I'm not sure what. It sends the email that the user needs to click but it doesn't tell them it's been sent.

Steps to reproduce:

  1. Set fos_user: registration: confirmation: enabled: true in config.yml
  2. Click on register
  3. Input email, username, password, confirmed password, submit
    Expected behavior: Render @FOSUser/Registration/check_email.html.twig
    Actual behavior: Redirected to login page

I see there's a doc on this

Registration success listener with enabled confirmation at the same time
------------------------------------------------------------------------

When you have registration confirmation and you want to hook up to
``FOSUserEvents::REGISTRATION_SUCCESS`` event you will have to prioritize this listener to be called
before ``FOS\UserBundle\EventListener\EmailConfirmationListener::onRegistrationSuccess``::

    public static function getSubscribedEvents()
    {
        return [
            FOSUserEvents::REGISTRATION_SUCCESS => [
                ['onRegistrationSuccess', -10],
            ],
        ];
    }

If you don't do it, ``EmailConfirmationListener`` will be called earlier and you will be redirected to
``fos_user_registration_check_email`` route.

But even after changing the priority of getSubscribedEvents in EmailConfirmationListener, it still doesn't redirect. The password reset redirects though.

It was something in the theme itself, I just had to edit a function onUserCreate()

    public function onUserCreated(FilterUserResponseEvent $event)
    {
        $user = $event->getUser();

        $message = \Swift_Message::newInstance()
            ->setSubject('['.$this->container->getParameter('app.project_name').'] New User Registration')
            ->setFrom($this->container->getParameter('app.email_from'))
            ->setTo($user->getEmail())
            ->setBody($this->container->get('templating')->render('AppBundle::Email/user_registered.html.twig', [
                'user' => $user,
            ]), 'text/html');

        $this->container->get('mailer')->send($message);

        $response = $event->getResponse();
        // $response->setTargetUrl($this->container->get('router')->generate('listing_my'));
        $response->setTargetUrl($this->container->get('router')->generate('fos_user_registration_check_email'));
    }