/**
  * In this method, actually create the user / account.
  *
  * NOTE: After this method is called, the $registrationFlow is DESTROYED, so you need to store all attributes
  * in your object as you need them.
  *
  * @param RegistrationFlow $registrationFlow
  * @return void
  */
 public function createUserAndAccount(RegistrationFlow $registrationFlow)
 {
     // Create the account
     $account = new Account();
     $account->setAccountIdentifier($registrationFlow->getEmail());
     $account->setCredentialsSource($registrationFlow->getEncryptedPassword());
     $account->setAuthenticationProviderName('Sandstorm.UserManagement:Login');
     // Assign preconfigured roles
     foreach ($this->rolesForNewUsers as $roleString) {
         $account->addRole(new Role($roleString));
     }
     // Create the user
     $user = new User();
     $name = new PersonName('', $registrationFlow->getAttributes()['firstName'], '', $registrationFlow->getAttributes()['lastName'], '', $registrationFlow->getEmail());
     $user->setName($name);
     // Assign them to each other and persist
     $this->getPartyService()->assignAccountToParty($account, $user);
     $this->getPartyRepository()->add($user);
     $this->accountRepository->add($account);
     $this->persistenceManager->whitelistObject($user);
     $this->persistenceManager->whitelistObject($user->getPreferences());
     $this->persistenceManager->whitelistObject($name);
     $this->persistenceManager->whitelistObject($account);
 }
 /**
  * Creates a user based on the given information
  *
  * The created user and account are automatically added to their respective repositories and thus be persisted.
  *
  * @param string $username The username of the user to be created.
  * @param string $password Password of the user to be created
  * @param string $firstName First name of the user to be created
  * @param string $lastName Last name of the user to be created
  * @param array $roleIdentifiers A list of role identifiers to assign
  * @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider"
  * @return User The created user instance
  * @api
  */
 public function createUser($username, $password, $firstName, $lastName, array $roleIdentifiers = null, $authenticationProviderName = null)
 {
     $user = new User();
     $name = new PersonName('', $firstName, '', $lastName, '', $username);
     $user->setName($name);
     return $this->addUser($username, $password, $user, $roleIdentifiers, $authenticationProviderName);
 }
 /**
  * Creates a temporary account
  *
  * @param string $accountIdentifier
  * @param string $password
  * @param string $firstName
  * @param string $lastName
  * @return Account
  */
 protected function createTemporaryAccount($accountIdentifier, $password, $firstName, $lastName)
 {
     if (strlen($firstName) === 0 && strlen($lastName) === 0) {
         $firstName = 'Santa';
         $lastName = 'Claus';
     }
     $user = new User();
     $user->setName(new PersonName('', $firstName, '', $lastName));
     $user->getPreferences()->set('context.workspace', 'user-' . $accountIdentifier);
     $this->partyRepository->add($user);
     $account = $this->accountFactory->createAccountWithPassword($accountIdentifier, $password, array('TYPO3.Neos:Editor'), 'Typo3BackendProvider');
     $account->setParty($user);
     $account->setExpirationDate(new \DateTime('+1 week'));
     $this->accountRepository->add($account);
 }