Question

I am using FOSUserBundle in my Symfony 2.3 project, and I want to execute some code right after the user confirms his account clicking on the email link. I was trying to override the

class RegistrationController extends ContainerAware 
{
...
} 

but no luck :(

Can I create any kind of Event to be executed right after this action?

Thanks!

Was it helpful?

Solution

You can create an EventListener which listens for FOSUserEvents::REGISTRATION_CONFIRMED like this:

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;

class RegistrationConfirmedEventListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(FOSUserEvents::REGISTRATION_CONFIRMED => 'performOnRegistrationConfirmed');
    }

    public function performOnRegistrationConfirmed(UserEvent $event)
    {
        $user = $event->getUser();
        // Do something
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top