Пример #1
0
 /**
  * @param Request $request
  * @return null|RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 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 = new CustomerUser();
     $user->setEnabled(true);
     $event = new GetResponseUserEvent($user, $request);
     $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     $form = $formFactory->createForm(['action' => $this->generateUrl('fos_user_registration_register')]);
     $form->setData($user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $event = new FormEvent($form, $request);
         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
         $userManager->updateUser($user);
         if (null === ($response = $event->getResponse())) {
             $url = $this->generateUrl('fos_user_registration_confirmed');
             $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()));
 }
Пример #2
0
 /**
  * @param CustomerUser $user
  * @return array
  */
 protected function _createUserArray(CustomerUser $user)
 {
     $data = [];
     $data['description'] = sprintf('%s (%s)', $user->getEmail(), $user->getName());
     $data['email'] = $user->getEmail();
     $data['metadata'] = ['salt' => $user->getSalt(), 'password' => $user->getPassword(), 'roles' => json_encode($user->getRoles()), 'internal_id' => $user->getId()];
     return $data;
 }
Пример #3
0
 /**
  * @param CustomerUser $user
  */
 public function __construct(CustomerUser $user)
 {
     $this->user = $user;
     $this->user->setBilling($this);
 }