/**
  * 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 DiamanteUser $user
  */
 protected function restoreUser(DiamanteUser $user)
 {
     $user->setDeleted(false);
     $user->updateTimestamp();
     $this->diamanteUserRepository->store($user);
     $this->resetPassword(new User($user->getId(), User::TYPE_DIAMANTE));
 }
 /**
  * @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 Command\RegisterCommand $command
  * @param DiamanteUser $user
  */
 protected function restoreUser(Command\RegisterCommand $command, DiamanteUser $user)
 {
     $user->setEmail($command->email);
     $user->setFirstName($command->firstName);
     $user->setLastName($command->lastName);
     $user->setDeleted(false);
     $user->getApiUser()->setPassword($command->password);
     $this->diamanteUserRepository->store($user);
 }
 /**
  * Update Diamante and Api users related to current session
  *
  * @ApiDoc(
  *  description="Update current user",
  *  uri="/users/current.{_format}",
  *  method={
  *      "PATCH",
  *      "PUT"
  *  },
  *  resource=true,
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized to update user",
  *      404="Returned when the user is not found"
  *  }
  * )
  *
  * @param UpdateUserCommand $command
  * @return DiamanteUser
  */
 public function update(UpdateUserCommand $command)
 {
     $apiUser = $this->authorizationService->getLoggedUser();
     $diamanteUser = $this->loadDiamanteUser($apiUser);
     if ($command->firstName) {
         $diamanteUser->setFirstName($command->firstName);
     }
     if ($command->lastName) {
         $diamanteUser->setLastName($command->lastName);
     }
     if ($command->password) {
         $apiUser->setPassword($command->password);
     }
     $this->diamanteUserRepository->store($diamanteUser);
     $this->apiUserRepository->store($apiUser);
     return $diamanteUser;
 }