/** * Create a new user * * This command creates a new user which has access to the backend user interface. * It is recommended to user the email address as a username. * * @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 string $roles A comma separated list of roles to assign * @FLOW3\Validate(argumentName="username", type="EmailAddress") * @return void */ public function createCommand($username, $password, $firstName, $lastName, $roles = NULL) { $account = $this->accountRepository->findByAccountIdentifierAndAuthenticationProviderName($username, 'Typo3BackendProvider'); if ($account instanceof \TYPO3\FLOW3\Security\Account) { $this->outputLine('User "%s" already exists.', array($username)); $this->quit(1); } $user = new \TYPO3\TYPO3\Domain\Model\User(); $name = new \TYPO3\Party\Domain\Model\PersonName('', $firstName, '', $lastName, '', $username); $user->setName($name); $workspaceName = 'user-' . preg_replace('/[^a-z0-9]/i', '', $username); $user->getPreferences()->set('context.workspace', $workspaceName); $this->partyRepository->add($user); $roles = empty($roles) ? array('Editor') : explode(',', $roles); $account = $this->accountFactory->createAccountWithPassword($username, $password, $roles, 'Typo3BackendProvider'); $account->setParty($user); $this->accountRepository->add($account); $this->outputLine('Created account "%s".', array($username)); }
/** * This method is called when the form of this step has been submitted * * @param array $formValues * @return void */ public function postProcessFormValues(array $formValues) { $user = new \TYPO3\TYPO3\Domain\Model\User(); $name = new \TYPO3\Party\Domain\Model\PersonName('', $formValues['firstName'], '', $formValues['lastName'], '', $formValues['username']); $user->setName($name); $user->getPreferences()->set('context.workspace', 'user-' . $formValues['username']); $this->partyRepository->add($user); $account = $this->accountFactory->createAccountWithPassword($formValues['username'], $formValues['password'], array('Administrator'), 'Typo3BackendProvider'); $account->setParty($user); $this->accountRepository->add($account); }
/** * @param string $identifier * @FLOW3\Validate(argumentName="identifier", type="NotEmpty") * @FLOW3\Validate(argumentName="identifier", type="StringLength", options={ "minimum"=1, "maximum"=255 }) * @FLOW3\Validate(argumentName="identifier", type="\TYPO3\TYPO3\Validation\Validator\AccountExistsValidator", options={ "authenticationProviderName"="Typo3BackendProvider" }) * @param array $password * @FLOW3\Validate(argumentName="password", type="\TYPO3\TYPO3\Validation\Validator\PasswordValidator", options={ "allowEmpty"=0, "minimum"=1, "maximum"=255 }) * @param string $firstName * @FLOW3\Validate(argumentName="firstName", type="NotEmpty") * @FLOW3\Validate(argumentName="firstName", type="StringLength", options={ "minimum"=1, "maximum"=255 }) * @param string $lastName * @FLOW3\Validate(argumentName="lastName", type="NotEmpty") * @FLOW3\Validate(argumentName="lastName", type="StringLength", options={ "minimum"=1, "maximum"=255 }) * @return void * @todo Security */ public function createAction($identifier, array $password, $firstName, $lastName) { $user = new \TYPO3\TYPO3\Domain\Model\User(); $name = new \TYPO3\Party\Domain\Model\PersonName('', $firstName, '', $lastName, '', $identifier); $user->setName($name); $user->getPreferences()->set('context.workspace', 'user-' . $identifier); $this->partyRepository->add($user); $account = $this->accountFactory->createAccountWithPassword($identifier, array_shift($password), array('Administrator'), 'Typo3BackendProvider'); $account->setParty($user); $this->accountRepository->add($account); $this->redirect('index'); }
/** * @param \Planetflow3\Domain\Model\User $object */ public function add($object) { $this->accountRepository->add($object->getPrimaryAccount()); parent::add($object); }