/**
  * @param $user
  */
 protected function discriminate($user)
 {
     $class = get_class($user);
     if (isset($this->users[$class])) {
         $this->userDiscriminator->setCurrentUser($this->users[$class]);
     }
 }
 /**
  * @return FormInterface
  */
 public function createForm()
 {
     $user = $this->userDiscriminator->getCurrentUserConfig();
     $type = $user->getFormType($this->type);
     $name = $user->getFormName($this->type);
     $validationGroups = $user->getFormValidationGroups($this->type);
     return $this->formFactory->createNamed($name, $type, null, array('validation_groups' => $validationGroups));
 }
 /**
  * {@inheritdoc}
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     // Already set
     if (null !== $this->userDiscriminator->getCurrentUser()) {
         return;
     }
     $request = $event->getRequest();
     foreach ($this->users as $name => $requestMatcher) {
         if ($requestMatcher->matches($request)) {
             $this->userDiscriminator->setCurrentUser($name);
             return;
         }
     }
 }
 public function onRegistrationSuccess(FormEvent $event)
 {
     if (!$this->userDiscriminator->getCurrentUserConfig()->getConfig('registering.confirmation.enabled', false)) {
         return;
     }
     /** @var $user \FOS\UserBundle\Model\UserInterface */
     $user = $event->getForm()->getData();
     $user->setEnabled(false);
     if (null === $user->getConfirmationToken()) {
         $user->setConfirmationToken($this->tokenGenerator->generateToken());
     }
     $this->mailer->sendConfirmationEmailMessage($user);
     $this->session->set('fos_user_send_confirmation_email/email', $user->getEmail());
     $url = $this->router->generate($this->userDiscriminator->getCurrentUserConfig()->getRoutePrefix() . '_registration_check_email');
     $event->setResponse(new RedirectResponse($url));
 }
 /**
  * This must be called on prePersist and preUpdate if the event is about a
  * user.
  *
  * @param UserInterface $user
  */
 protected function updateUserFields(UserInterface $user)
 {
     if (null === $this->userDiscriminator) {
         $this->userDiscriminator = $this->container->get('rollerworks_multi_user.user_discriminator');
     }
     // Can only use the user manager when there is an user-system active
     if (null === $this->userDiscriminator->getCurrentUser() || true !== $this->userDiscriminator->getCurrentUserConfig()->getConfig('use_listener', true)) {
         return;
     }
     if (null === $this->userManager) {
         $this->userManager = $this->container->get('fos_user.user_manager');
     }
     $this->userManager->updateCanonicalFields($user);
     $this->userManager->updatePassword($user);
 }
 public function dispatchSecurityImplicitLogin(Event $e)
 {
     if ($userSys = $this->userDiscriminator->getCurrentUser()) {
         $this->eventDispatcher->dispatch($userSys . '.security.implicit_login', $e);
     }
 }