/**
  * Saves content draft corresponding to $data.
  * Depending on the nature of $data (create or update data), the draft will either be created or simply updated.
  *
  * @param ContentStruct|\EzSystems\RepositoryForms\Data\User\UserCreateData $data
  * @param $languageCode
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 private function saveDraft(UserCreateData $data, $languageCode)
 {
     foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) {
         if ($fieldData->getFieldTypeIdentifier() !== 'ezuser') {
             $data->setField($fieldDefIdentifier, $fieldData->value, $languageCode);
         }
     }
     return $this->repository->sudo(function () use($data) {
         return $this->userService->createUser($data, $data->getParentGroups());
     });
 }
예제 #2
0
 /**
  * @Given /^there is a User Content$/
  */
 public function thereIsAUserContent()
 {
     $login = '******' . microtime(true);
     $email = $login . '@example.com';
     $struct = $this->userService->newUserCreateStruct($login, $email, 'publish', 'eng-GB');
     $struct->setField('first_name', 'John');
     $struct->setField('last_name', 'Doe');
     $parentGroup = $this->userService->loadUserGroup(11);
     $user = $this->userService->createUser($struct, [$parentGroup]);
     $this->currentContent = $this->contentService->loadContentByContentInfo($user->contentInfo);
 }
 /**
  * @inheritdoc
  */
 public function visit(TreeNodeInterface $node, &$data)
 {
     if (!is_array($data)) {
         return null;
     }
     if (!$this->isExistingUser($data['login'])) {
         $userStruct = $this->getUserStruct($data);
         $userGroups = $this->getParentGroups($data);
         $user = $this->userService->createUser($userStruct, $userGroups);
     } else {
         $user = $this->userService->loadUserByLogin($data['login']);
         // @todo: update of user object is not implemented
     }
     if (isset($data['roles'])) {
         foreach ($data['roles'] as $roleId) {
             $role = $this->repository->getRoleService()->loadRoleByIdentifier($roleId);
             // @doc: parameter RoleLimitation is not supported.
             // Not possible to assign role to user or group with limitation
             $this->repository->getRoleService()->assignRoleToUser($role, $user);
         }
     }
     return $user;
 }
예제 #4
0
 /**
  * Create a new user group in the given group
  *
  * @param $groupPath
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  * @return \eZ\Publish\Core\REST\Server\Values\CreatedUser
  */
 public function createUser($groupPath)
 {
     $userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($groupPath));
     $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);
     $userCreateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $this->request->headers->get('Content-Type')), $this->request->getContent()));
     try {
         $createdUser = $this->userService->createUser($userCreateStruct, array($userGroup));
     } catch (InvalidArgumentException $e) {
         throw new ForbiddenException($e->getMessage());
     }
     $createdContentInfo = $createdUser->getVersionInfo()->getContentInfo();
     $createdLocation = $this->locationService->loadLocation($createdContentInfo->mainLocationId);
     $contentType = $this->contentTypeService->loadContentType($createdContentInfo->contentTypeId);
     return new Values\CreatedUser(array('user' => new Values\RestUser($createdUser, $contentType, $createdContentInfo, $createdLocation, $this->contentService->loadRelations($createdUser->getVersionInfo()))));
 }
예제 #5
0
 /**
  * Create user inside given User Group; DELETES existing User if login already exists!
  *
  * @param $username username of the user to create
  * @param $email email address of user to create
  * @param $password account password for user to create
  * @param $parentGroup pathstring wherein to create user
  *
  * @return eZ\Publish\API\Repository\Values\User\User
  */
 protected function createUser($username, $email, $password, $parentGroup = null, $fields = array())
 {
     $userCreateStruct = $this->userService->newUserCreateStruct($username, $email, $password, self::DEFAULT_LANGUAGE);
     $userCreateStruct->setField('first_name', $username);
     $userCreateStruct->setField('last_name', $username);
     foreach ($fields as $fieldName => $fieldValue) {
         $userCreateStruct->setField($fieldName, $fieldValue);
     }
     try {
         $existingUser = $this->userService->loadUserByLogin($username);
         $this->userService->deleteUser($existingUser);
     } catch (NotFoundException $e) {
         // do nothing
     }
     if (!$parentGroup) {
         $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID);
     }
     $user = $this->userService->createUser($userCreateStruct, array($parentGroup));
     return $user;
 }
 /**
  * Create a new user. The created user is published by this method
  *
  * @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct the data used for creating the user
  * @param array $parentGroups the groups of type {@link \eZ\Publish\API\Repository\Values\User\UserGroup} which are assigned to the user after creation
  *
  * @return \eZ\Publish\API\Repository\Values\User\User
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userCreateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or set  to an empty value
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a field value is not accepted by the field type
  *                                                                        if a user with provided login already exists
  */
 public function createUser(UserCreateStruct $userCreateStruct, array $parentGroups)
 {
     $returnValue = $this->service->createUser($userCreateStruct, $parentGroups);
     $this->signalDispatcher->emit(new CreateUserSignal(array('userId' => $returnValue->id)));
     return $returnValue;
 }