public function registerAction(Request $request)
 {
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->get('fos_user.registration.form.factory');
     /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
     $userManager = $this->get('fos_user.user_manager');
     /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
     $dispatcher = $this->get('event_dispatcher');
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $event = new GetResponseUserEvent($user, $request);
     $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     $form = $formFactory->createForm();
     $form->setData($user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $event = new FormEvent($form, $request);
         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
         // Ajout pour SnoozIt
         $avatar_default = $this->container->get('doctrine')->getManager()->getRepository('SnoozitUserBundle:Avatar')->find(1);
         $user->setAvatar($avatar_default);
         $userManager->updateUser($user);
         // Logs SnoozIt
         $dispatcher->dispatch(SkuagEvents::ON_REGISTRATION_SUCCESS, new RegistrationSuccess($user));
         $notification = new Notification();
         $notification->setUser($user);
         if (null === ($response = $event->getResponse())) {
             $url = $this->generateUrl('snoozit_dashboard_homepage');
             $response = new RedirectResponse($url);
         }
         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
         return $response;
     }
     return $this->render('FOSUserBundle:Registration:register.html.twig', array('form' => $form->createView()));
 }
 private function injectData()
 {
     $userData = $this->getUserNotificationAccount();
     if (!$userData) {
         $notificationEngine = new Notification();
         $this->form->setData($notificationEngine->setUser($this->getUser()));
         return;
     }
     $this->form->setData($userData);
     if (empty($this->form->get('newsletter')->getData())) {
         $this->form->get('newsletter')->setData('0');
     }
     if (empty($this->form->get('advertInterest')->getData())) {
         $this->form->get('advertInterest')->setData('0');
     }
     if (empty($this->form->get('follower')->getData())) {
         $this->form->get('follower')->setData('0');
     }
     if (empty($this->form->get('comment')->getData())) {
         $this->form->get('comment')->setData('0');
     }
     return;
 }
Example #3
0
 private function createNotification($user)
 {
     $notification = new Notification();
     $notification->setUser($user);
     return $notification;
 }