/**
  * Confirm user registration
  * @param Command\ConfirmCommand $command
  * @return void
  */
 public function confirm(Command\ConfirmCommand $command)
 {
     $apiUser = $this->apiUserRepository->findUserByHash($command->hash);
     if (is_null($apiUser)) {
         throw new \RuntimeException('Can not confirm registration.');
     }
     try {
         $apiUser->activate($command->hash);
         $this->apiUserRepository->store($apiUser);
     } catch (\Exception $e) {
         throw new \RuntimeException('Can not confirm registration.');
     }
 }
 /**
  * @param ChangePasswordCommand $command
  * @return void
  */
 public function changePassword(ChangePasswordCommand $command)
 {
     /**
      * @var ApiUser $apiUser
      */
     $apiUser = $this->apiUserRepository->findUserByHash($command->hash);
     if (is_null($apiUser)) {
         throw new \RuntimeException('Your password reset link has expired.');
     }
     $apiUser->changePassword($command->password);
     $this->apiUserRepository->store($apiUser);
 }
 /**
  * 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;
 }