<commit_before><?php

namespace AppBundle\EventListener;

use Doctrine\ORM\EntityManager;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;

/**
 * Listener responsible for sending an email and prevent registration if
 * profile does not exists.
 */
class RegistrationListener implements EventSubscriberInterface
{
    private $router;

    private $templating;

    private $mailer;

    private $em;

    private $userManager;

    private $formFactory;

    public function __construct(
        UrlGeneratorInterface $router,
        EngineInterface $templating,
        \Swift_Mailer $mailer,
        EntityManager $em,
        $userManager,
        $formFactory
    ) {
        $this->router = $router;
        $this->templating = $templating;
        $this->mailer = $mailer;
        $this->em = $em;
        $this->userManager = $userManager;
        $this->formFactory = $formFactory;
    }

    /**
     * {@inheritDoc}
     */
    public static function getSubscribedEvents()
    {
        return array(
            FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegistrationInitialize',
            FOSUserEvents::REGISTRATION_SUCCESS => array('onRegistrationSuccess', -1),
        );
    }

    /**
     * When user created
     */
    public function onRegistrationSuccess(FormEvent $event)
    {
        $user = $event->getForm()->getData();
        $profile = $this->em
            ->getRepository('AppBundle:Adherent')
            ->findOneByEmail($user->getEmail());
        $user->setProfile($profile);

        $url = $this->router->generate('custom_user_registration_check_email', array(
            'email' => $user->getEmail(),
        ));
        $event->setResponse(new RedirectResponse($url));
    }

    /**
     * If form is valid but profile does not exists.
     */
    public function onRegistrationInitialize(GetResponseUserEvent $event)<commit_msg>code comment on registration process<commit_after><?php

namespace AppBundle\EventListener;

use Doctrine\ORM\EntityManager;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;

/**
 * Listener responsible for sending an email and prevent registration if
 * profile does not exists.
 */
class RegistrationListener implements EventSubscriberInterface
{
    private $router;

    private $templating;

    private $mailer;

    private $em;

    private $userManager;

    private $formFactory;

    public function __construct(
        UrlGeneratorInterface $router,
        EngineInterface $templating,
        \Swift_Mailer $mailer,
        EntityManager $em,
        $userManager,
        $formFactory
    ) {
        $this->router = $router;
        $this->templating = $templating;
        $this->mailer = $mailer;
        $this->em = $em;
        $this->userManager = $userManager;
        $this->formFactory = $formFactory;
    }

    /**
     * {@inheritDoc}
     */
    public static function getSubscribedEvents()
    {
        return array(
            FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegistrationInitialize',
            FOSUserEvents::REGISTRATION_SUCCESS => array('onRegistrationSuccess', -1),
        );
    }

    /**
     * When user created we link adherent profile to user.
     */
    public function onRegistrationSuccess(FormEvent $event)
    {
        $user = $event->getForm()->getData();
        $profile = $this->em
            ->getRepository('AppBundle:Adherent')
            ->findOneByEmail($user->getEmail());
        $user->setProfile($profile);

        $url = $this->router->generate('custom_user_registration_check_email', array(
            'email' => $user->getEmail(),
        ));
        $event->setResponse(new RedirectResponse($url));
    }

    /**
     * If form is valid but profile does not exists, we fake correct registration
     * otherwise anyone could known who is member of the Parti de Gauche.
     */
    public function onRegistrationInitialize(GetResponseUserEvent $event)
{'fraction_non_alphanumeric': 0.10726872246696036, 'fraction_numerical': 0.0004405286343612335, 'mean_word_length': 3.004409171075838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5521846', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1229, 'n_words': 265}