/**
  * Register new Diamante User and grant API access for it.
  * Sends confirmation email. While registration is not confirmed API access is not active
  * @param Command\RegisterCommand $command
  * @return void
  */
 public function register(Command\RegisterCommand $command)
 {
     $diamanteUser = $this->diamanteUserFactory->create($command->email, $command->firstName, $command->lastName);
     $apiUser = $this->apiUserFactory->create($command->email, $command->password);
     if ($this->diamanteUserRepository->findUserByEmail($command->email)) {
         throw new \RuntimeException('An account with this email address already exists');
     }
     $diamanteUser->setApiUser($apiUser);
     $this->diamanteUserRepository->store($diamanteUser);
     $this->registrationMailer->sendConfirmationEmail($diamanteUser->getEmail(), $apiUser->getHash());
 }
 /**
  * @param Message $message
  * @param Ticket $ticket
  */
 private function processWatchers(Message $message, $ticket)
 {
     if (!$ticket) {
         return;
     }
     /** @var Message\MessageRecipient $recipient */
     foreach ($message->getRecipients() as $recipient) {
         $email = $recipient->getEmail();
         if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) {
             continue;
         }
         $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email);
         $oroUser = $this->oroUserManager->findUserByEmail($email);
         if ($oroUser) {
             $user = new User($oroUser->getId(), User::TYPE_ORO);
         } elseif ($diamanteUser) {
             $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE);
         } else {
             $diamanteUser = $this->diamanteUserFactory->create($email, $recipient->getFirstName(), $recipient->getLastName());
             $this->diamanteUserRepository->store($diamanteUser);
             $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE);
         }
         $this->watchersService->addWatcher($ticket, $user);
     }
 }
 /**
  * @param \Diamante\UserBundle\Api\Command\CreateDiamanteUserCommand $command
  *
  * @return int
  */
 public function createDiamanteUser(CreateDiamanteUserCommand $command)
 {
     $user = $this->diamanteUserRepository->findUserByEmail($command->email);
     if (!is_null($user)) {
         if (true === $user->isDeleted()) {
             $this->restoreUser($user);
             return $user->getId();
         } else {
             throw new DiamanteUserExistsException('An account with this email address already exists');
         }
     }
     $user = $this->factory->create($command->email, $command->firstName, $command->lastName);
     $apiUser = new ApiUserEntity($command->email, static::generateRandomSequence(16), static::generateRandomSequence(64), $user);
     $apiUser->generateHash();
     $user->setDeleted(false);
     $user->setApiUser($apiUser);
     $this->notifier->notifyByScenario('created', $user, ['activation_hash' => $user->getApiUser()->getHash()]);
     $this->diamanteUserRepository->store($user);
     return $user->getId();
 }