/**
  * @param RegistrationFlow $registrationFlow
  */
 public function registerAction(RegistrationFlow $registrationFlow)
 {
     // We remove already existing flows
     $alreadyExistingFlows = $this->registrationFlowRepository->findByEmail($registrationFlow->getEmail());
     if (count($alreadyExistingFlows) > 0) {
         foreach ($alreadyExistingFlows as $alreadyExistingFlow) {
             $this->registrationFlowRepository->remove($alreadyExistingFlow);
         }
     }
     $registrationFlow->storeEncryptedPassword();
     // Send out a confirmation mail
     $activationLink = $this->uriBuilder->reset()->setCreateAbsoluteUri(true)->uriFor('activateAccount', ['token' => $registrationFlow->getActivationToken()], 'Registration');
     $this->emailService->sendTemplateBasedEmail('ActivationToken', $this->subjectActivation, [$this->emailSenderAddress => $this->emailSenderName], [$registrationFlow->getEmail()], ['activationLink' => $activationLink, 'applicationName' => $this->emailSenderName, 'registrationFlow' => $registrationFlow, 'baseUri' => htmlspecialchars($this->controllerContext->getRequest()->getHttpRequest()->getBaseUri())]);
     $this->registrationFlowRepository->add($registrationFlow);
     $this->view->assign('email', $registrationFlow->getEmail());
 }
 /**
  * Create User on the Command Line
  *
  * @param string $username The email address, which also serves as the username.
  * @param string $password This user's password.
  * @param string $additionalAttributes Additional attributes to pass to the registrationFlow as semicolon-separated list. Example: ./flow sandstormuser:create ... --additionalAttributes="customerType:CUSTOMER;color:blue"
  */
 public function createCommand($username, $password, $additionalAttributes = '')
 {
     // Parse additionalAttributes if they exist
     $attributes = [];
     if (strlen($additionalAttributes) > 0) {
         $attributesSplitBySeparator = explode(';', $additionalAttributes);
         array_map(function ($singleAttribute) use(&$attributes) {
             $splitAttribute = explode(':', $singleAttribute);
             $attributes[$splitAttribute[0]] = $splitAttribute[1];
         }, $attributesSplitBySeparator);
     }
     $passwordDto = new PasswordDto();
     $passwordDto->setPassword($password);
     $passwordDto->setPasswordConfirmation($password);
     $registrationFlow = new RegistrationFlow();
     $registrationFlow->setPasswordDto($passwordDto);
     $registrationFlow->setEmail($username);
     $registrationFlow->setAttributes($attributes);
     // Remove existing registration flows
     $alreadyExistingFlows = $this->registrationFlowRepository->findByEmail($registrationFlow->getEmail());
     if (count($alreadyExistingFlows) > 0) {
         foreach ($alreadyExistingFlows as $alreadyExistingFlow) {
             $this->registrationFlowRepository->remove($alreadyExistingFlow);
         }
     }
     $registrationFlow->storeEncryptedPassword();
     // Store the RF and persist so the activate command will find it
     $this->registrationFlowRepository->add($registrationFlow);
     $this->persistenceManager->persistAll();
     // Directly activate the account
     $this->activateRegistrationCommand($username);
     $this->outputLine('Added the User <b>"%s"</b> with password <b>"%s"</b>.', [$username, $password]);
 }