public function registerUser(array $data, array $selectedCollections = null, $providerId = null)
 {
     $provider = null;
     if ($providerId !== null) {
         $provider = $this->oauthProviderCollection->get($providerId);
     }
     $inscriptions = $this->registrationManager->getRegistrationSummary();
     $authorizedCollections = $this->getAuthorizedCollections($selectedCollections, $inscriptions);
     if (!isset($data['login'])) {
         $data['login'] = $data['email'];
     }
     $user = $this->userManipulator->createUser($data['login'], $data['password'], $data['email'], false);
     if (isset($data['geonameid'])) {
         $this->userManipulator->setGeonameId($user, $data['geonameid']);
     }
     foreach (self::$userPropertySetterMap as $property => $method) {
         if (isset($data[$property])) {
             call_user_func(array($user, $method), $data[$property]);
         }
     }
     $this->entityManager->persist($user);
     $this->entityManager->flush($user);
     if (null !== $provider) {
         $this->attachProviderToUser($provider, $user);
         $this->entityManager->flush();
     }
     $this->applyAclsToUser($authorizedCollections, $user);
     $this->createCollectionAccessDemands($user, $authorizedCollections);
     $user->setMailLocked(true);
     return $user;
 }