/**
  * Render user initials or an abbreviated name for a given username. If the account was deleted, use the username as fallback.
  *
  * @param string $format Supported are "fullFirstName" and "initials"
  * @return string
  */
 public function render($format = 'initials')
 {
     if (!in_array($format, array('fullFirstName', 'initials', 'fullName'))) {
         throw new \InvalidArgumentException(sprintf('Format "%s" given to history:userInitials(), only supporting "fullFirstName", "initials" and "fullName".', $format), 1415705861);
     }
     $username = $this->renderChildren();
     /* @var $requestedUser Person */
     $requestedUser = $this->domainUserService->getUser($username);
     if ($requestedUser === null || $requestedUser->getName() === null) {
         return $username;
     }
     $currentUser = $this->userService->getBackendUser();
     if ($currentUser) {
         if ($currentUser === $requestedUser) {
             $translationHelper = new TranslationHelper();
             $you = $translationHelper->translate('you', null, [], 'Main', 'TYPO3.Neos');
         }
     }
     switch ($format) {
         case 'initials':
             return mb_substr($requestedUser->getName()->getFirstName(), 0, 1) . mb_substr($requestedUser->getName()->getLastName(), 0, 1);
         case 'fullFirstName':
             return isset($you) ? $you : $requestedUser->getName()->getFirstName() . ' ' . mb_substr($requestedUser->getName()->getLastName(), 0, 1) . '.';
         case 'fullName':
             return isset($you) ? $you : $requestedUser->getName()->getFullName();
     }
 }
 /**
  * Returns TRUE, if the specified user ($value) does not exist yet.
  *
  * If at least one error occurred, the result is FALSE.
  *
  * @param mixed $value The value that should be validated
  * @return void
  * @throws InvalidSubjectException
  */
 protected function isValid($value)
 {
     if (!is_string($value)) {
         throw new InvalidSubjectException('The given username was not a string.', 1325155784);
     }
     if ($this->userService->getUser($value) !== null) {
         $this->addError('The username is already in use.', 1325156008);
     }
 }
 /**
  * Retrieves the given user or fails by exiting with code 1 and a message
  *
  * @param string $username Username of the user to find
  * @param string $authenticationProviderName Name of the authentication provider to use
  * @return User The user
  * @throws Exception
  */
 protected function getUserOrFail($username, $authenticationProviderName)
 {
     $user = $this->userService->getUser($username, $authenticationProviderName);
     if (!$user instanceof User) {
         $this->outputLine('The user "%s" does not exist.', array($username));
         $this->quit(1);
     }
     return $user;
 }
 /**
  * Create a workspace
  *
  * @param string $workspaceName
  * @param Workspace $baseWorkspace
  * @param string $ownerAccountIdentifier
  * @return string
  */
 public function createAction($workspaceName, Workspace $baseWorkspace, $ownerAccountIdentifier = null)
 {
     $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
     if ($existingWorkspace !== null) {
         $this->throwStatus(409, 'Workspace already exists', '');
     }
     if ($ownerAccountIdentifier !== null) {
         $owner = $this->userService->getUser($ownerAccountIdentifier);
         if ($owner === null) {
             $this->throwStatus(422, 'Requested owner account does not exist', '');
         }
     } else {
         $owner = null;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
     $this->workspaceRepository->add($workspace);
     $this->throwStatus(201, 'Workspace created', '');
 }
 /**
  * Update a given account
  *
  * @param Account $account The account to update
  * @param array $roleIdentifiers A possibly updated list of roles for the user's primary account
  * @param array $password Expects an array in the format array('<password>', '<password confirmation>')
  * @Flow\Validate(argumentName="password", type="\TYPO3\Neos\Validation\Validator\PasswordValidator", options={ "allowEmpty"=1, "minimum"=1, "maximum"=255 })
  * @return void
  */
 public function updateAccountAction(Account $account, array $roleIdentifiers, array $password = array())
 {
     $user = $this->userService->getUser($account->getAccountIdentifier(), $account->getAuthenticationProviderName());
     if ($user === $this->currentUser) {
         $roles = array();
         foreach ($roleIdentifiers as $roleIdentifier) {
             $roles[$roleIdentifier] = $this->policyService->getRole($roleIdentifier);
         }
         if (!$this->privilegeManager->isPrivilegeTargetGrantedForRoles($roles, 'TYPO3.Neos:Backend.Module.Administration.Users')) {
             $this->addFlashMessage('With the selected roles the currently logged in user wouldn\'t have access to this module any longer. Please adjust the assigned roles!', 'Don\'t lock yourself out', Message::SEVERITY_WARNING, array(), 1416501197);
             $this->forward('edit', null, null, array('user' => $this->currentUser));
         }
     }
     $password = array_shift($password);
     if (strlen(trim(strval($password))) > 0) {
         $this->userService->setUserPassword($user, $password);
     }
     $this->userService->setRolesForAccount($account, $roleIdentifiers);
     $this->addFlashMessage('The account has been updated.', 'Account updated', Message::SEVERITY_OK);
     $this->redirect('edit', null, null, array('user' => $user));
 }
 /**
  * Create a new workspace
  *
  * This command creates a new workspace.
  *
  * @param string $workspace Name of the workspace, for example "christmas-campaign"
  * @param string $baseWorkspace Name of the base workspace. If none is specified, "live" is assumed.
  * @param string $title Human friendly title of the workspace, for example "Christmas Campaign"
  * @param string $description A description explaining the purpose of the new workspace
  * @param string $owner The identifier of a User to own the workspace
  * @return void
  */
 public function createCommand($workspace, $baseWorkspace = 'live', $title = null, $description = null, $owner = '')
 {
     $workspaceName = $workspace;
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if ($workspace instanceof Workspace) {
         $this->outputLine('Workspace "%s" already exists', [$workspaceName]);
         $this->quit(1);
     }
     $baseWorkspaceName = $baseWorkspace;
     $baseWorkspace = $this->workspaceRepository->findOneByName($baseWorkspaceName);
     if (!$baseWorkspace instanceof Workspace) {
         $this->outputLine('The base workspace "%s" does not exist', [$baseWorkspaceName]);
         $this->quit(2);
     }
     if ($owner === '') {
         $owningUser = null;
     } else {
         $owningUser = $this->userService->getUser($owner);
         if ($owningUser === null) {
             $this->outputLine('The user "%s" specified as owner does not exist', [$owner]);
             $this->quit(3);
         }
     }
     if ($title === null) {
         $title = $workspaceName;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace, $owningUser);
     $workspace->setTitle($title);
     $workspace->setDescription($description);
     $this->workspaceRepository->add($workspace);
     if ($owningUser instanceof User) {
         $this->outputLine('Created a new workspace "%s", based on workspace "%s", owned by "%s".', [$workspaceName, $baseWorkspaceName, $owner]);
     } else {
         $this->outputLine('Created a new workspace "%s", based on workspace "%s".', [$workspaceName, $baseWorkspaceName]);
     }
 }
 /**
  * Edit the given account
  *
  * @param Account $account
  * @return void
  */
 public function editAccountAction(Account $account)
 {
     $this->view->assignMultiple(array('account' => $account, 'user' => $this->userService->getUser($account->getAccountIdentifier(), $account->getAuthenticationProviderName())));
 }