/** * 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 pre-configured roles foreach ($this->rolesForNewUsers as $roleString) { $account->addRole(new Role($roleString)); } // Create the user $user = new User(); $user->setAccount($account); $user->setEmail($registrationFlow->getEmail()); if (array_key_exists('salutation', $registrationFlow->getAttributes())) { $user->setGender($registrationFlow->getAttributes()['salutation']); } if (array_key_exists('firstName', $registrationFlow->getAttributes())) { $user->setFirstName($registrationFlow->getAttributes()['firstName']); } if (array_key_exists('lastName', $registrationFlow->getAttributes())) { $user->setLastName($registrationFlow->getAttributes()['lastName']); } // Persist user $this->userRepository->add($user); $this->persistenceManager->whitelistObject($user); $this->persistenceManager->whitelistObject($account); }
/** * Lists all available users. */ public function listUsersCommand() { // If we're in Neos context, we pass on the command. if ($this->shouldUseNeosService()) { $cliRequest = new Request($this->request); $cliRequest->setControllerObjectName(UserCommandController::class); $cliRequest->setControllerCommandName('list'); $cliResponse = new Response($this->response); $this->dispatcher->dispatch($cliRequest, $cliResponse); return; } /** @var User[] $users */ $users = $this->userRepository->findAll()->toArray(); usort($users, function ($a, $b) { /** @var User $a */ /** @var User $b */ return $a->getEmail() > $b->getEmail(); }); $tableRows = []; $headerRow = ['Email', 'Name', 'Role(s)']; foreach ($users as $user) { $tableRows[] = [$user->getEmail(), $user->getFullName(), implode(' ,', $user->getAccount()->getRoles())]; } $this->output->outputTable($tableRows, $headerRow); $this->outputLine(sprintf(' <b>%s users total.</b>', count($users))); }