@param array|JsonSerializable|User $data
@param string $userId

@throws UnprocessableEntityException The input data does not valid

@return User
506857
public function create($data, $userId = null)
    {
        if (isset($userId)) {
            return $this->client()->put($data, 'users/{userId}', ['userId' => $userId]);
        }

        return $this->client()->post($data, 'users');
    }
798600
public function DeleteUserData($UserID, $Options = array(), &$Data = NULL) {
      $SQL = Gdn::SQL();
      
      // Remove discussion watch records and drafts.
		$SQL->Delete('UserDiscussion', array('UserID' => $UserID));
      
		Gdn::UserModel()->GetDelete('Draft', array('InsertUserID' => $UserID), $Data);
      
      // Comment deletion depends on method selected
      $DeleteMethod = GetValue('DeleteMethod', $Options, 'delete');
      if ($DeleteMethod == 'delete') {
         // Clear out the last posts to the categories.
         $SQL
            ->Update('Category c')
            ->Join('Discussion d', 'd.DiscussionID = c.LastDiscussionID')
            ->Where('d.InsertUserID', $UserID)
            ->Set('c.LastDiscussionID', NULL)
            ->Set('c.LastCommentID', NULL)
            ->Put();
         
         $SQL
            ->Update('Category c')
            ->Join('Comment d', 'd.CommentID = c.LastCommentID')
            ->Where('d.InsertUserID', $UserID)
            ->Set('c.LastDiscussionID', NULL)
            ->Set('c.LastCommentID', NULL)
            ->Put();
         
         // Grab all of the discussions that the user has engaged in.
         $DiscussionIDs = $SQL
            ->Select('DiscussionID')
            ->From('Comment')
            ->Where('InsertUserID', $UserID)
            ->GroupBy('DiscussionID')
            ->Get()->ResultArray();
         $DiscussionIDs = ConsolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID');

         
         Gdn::UserModel()->GetDelete('Comment', array('InsertUserID' => $UserID), $Data);
         
         // Update the comment counts.
         $CommentCounts = $SQL
            ->Select('DiscussionID')
            ->Select('CommentID', 'count', 'CountComments')
            ->Select('CommentID', 'max', 'LastCommentID')
            ->WhereIn('DiscussionID', $DiscussionIDs)
            ->GroupBy('DiscussionID')
            ->Get('Comment')->ResultArray();
         
         foreach ($CommentCounts as $Row) {
            $SQL->Put('Discussion',
               array('CountComments' => $Row['CountComments'] + 1, 'LastCommentID' => $Row['LastCommentID']),
               array('DiscussionID' => $Row['DiscussionID']));
         }
         
         // Update the last user IDs.
         $SQL->Update('Discussion d')
            ->Join('Comment c', 'd.LastCommentID = c.CommentID', 'left')
            ->Set('d.LastCommentUserID', 'c.InsertUserID', FALSE, FALSE)
            ->Set('d.DateLastComment', 'c.DateInserted', FALSE, FALSE)
            ->WhereIn('d.DiscussionID', $DiscussionIDs)
            ->Put();
         
         // Update the last posts.
         $Discussions = $SQL
            ->WhereIn('DiscussionID', $DiscussionIDs)
            ->Where('LastCommentUserID', $UserID)
            ->Get('Discussion');
         
         // Delete the user's dicussions 
         Gdn::UserModel()->GetDelete('Discussion', array('InsertUserID' => $UserID), $Data);
         
         // Update the appropriat recent posts in the categories.
         $CategoryModel = new CategoryModel();
         $Categories = $CategoryModel->GetWhere(array('LastDiscussionID' => NULL))->ResultArray();
         foreach ($Categories as $Category) {
            $CategoryModel->SetRecentPost($Category['CategoryID']);
         }
      } else if ($DeleteMethod == 'wipe') {
         // Erase the user's dicussions
         $SQL->Update('Discussion')
            ->Set('Body', T('The user and all related content has been deleted.'))
            ->Set('Format', 'Deleted')
            ->Where('InsertUserID', $UserID)
            ->Put();

         $SQL->Update('Comment')
            ->Set('Body', T('The user and all related content has been deleted.'))
            ->Set('Format', 'Deleted')
            ->Where('InsertUserID', $UserID)
            ->Put();
      } else {
         // Leave comments
      }

      // Remove the user's profile information related to this application
      $SQL->Update('User')
         ->Set(array(
				'CountDiscussions' => 0,
				'CountUnreadDiscussions' => 0,
				'CountComments' => 0,
				'CountDrafts' => 0,
				'CountBookmarks' => 0
			))
         ->Where('UserID', $UserID)
         ->Put();
   }
712903
protected function createUser(array $data, UserProviderInterface $userManager)
    {
        $userIdentityfield = $this->container->getParameter('rch_jwt_user.user_identity_field');

        $user = $userManager->createUser()
            ->setUsername($data[$userIdentityfield])
            ->setEmail($data[$userIdentityfield])
            ->setEnabled(true)
            ->setPlainPassword($data['password']);

        if (isset($data['facebook_id'])) {
            $user->setFacebookId($data['facebook_id']);
        }

        try {
            $userManager->updateUser($user);
        } catch (\Exception $e) {
            $message = $e->getMessage() ?: 'An error occured while creating the user.';

            throw new UserException(422, $message, $e);
        }

        return $user;
    }
548188
public function addUser($userId)
    {
        if (true === is_numeric($userId) && false === in_array($userId, $this->users)) {
            $this->users[] = (int)$userId;
        }
        return $this;
    }
413137
public function loadUser($userId)
    {
        $user = $this->userService->loadUser($userId, Language::ALL);

        $userContentInfo = $user->getVersionInfo()->getContentInfo();
        $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);

        try {
            $userMainLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
            $relations = $this->contentService->loadRelations($user->getVersionInfo());
        } catch (UnauthorizedException $e) {
            // TODO: Hack for special case to allow current logged in user to load him/here self (but not relations)
            if ($user->id == $this->repository->getCurrentUser()->id) {
                $userMainLocation = $this->repository->sudo(
                    function () use ($userContentInfo) {
                        return $this->locationService->loadLocation($userContentInfo->mainLocationId);
                    }
                );
                // user may not have permissions to read related content, for security reasons do not use sudo().
                $relations = array();
            } else {
                throw $e;
            }
        }

        return new Values\CachedValue(
            new Values\RestUser(
                $user,
                $contentType,
                $userContentInfo,
                $userMainLocation,
                $relations
            ),
            array('locationId' => $userContentInfo->mainLocationId)
        );
    }
1182155
public function getUserCapabilities(string $userId): array
    {
        if (empty($this->userCapabilities)) {
            $this->userCapabilities = Utils::fetchUserCapabilities($userId);
        }

        return $this->userCapabilities;
    }
1256894
public function create($userId=null, $eventLog=null, $eventData=null)
    {
        if(is_null($userId)) throw new \Exception('User ID is required.');
        if(is_null($eventLog)) throw new \Exception('Event Log is required.');
        if(!is_numeric($userId)) throw new \Exception("Invalid User ID.");

        $id = $this->save($this->generateEntity(intval($userId), $eventLog, $eventData));
        return $id;
    }
750665
public function groupSync($userId, $data = array()) {
        try{
            if(empty($userId))
                throw new Exception('被同步群信息的用户 Id 不能为空');
            if(empty($data))
                throw new Exception('该用户的群信息 不能为空');
            $arrKey = array_keys($data);
            $arrVal = array_values($data);
            $params = array(
                'userId' => $userId
            );
            foreach ($data as $key => $value) {
                $params['group[' . $key . ']'] = $value;
            }

            $ret = $this->curl('/group/sync', $params);
            if(empty($ret))
                throw new Exception('请求失败');
            return $ret;
        }catch (Exception $e) {
            print_r($e->getMessage());
        }
    }
614814
private function createBatch($userId)
    {
        $entity = new EBatch();
        $entity->setUserRef($userId);
        $result = $this->daoBatch->create($entity);
        return $result;
    }
959459
protected function getUser($userId = null)
    {
        if ($userId === null) {
            /** @var Token $sessionAuth */
            if ($this->session()->isStarted() && $sessionAuth = $this->session()->get('authentication')) {
                return $sessionAuth->getUser();
            }

            return false;
        }
        /** @var Repository\UsersRepository $repo */
        $repo = $this->storage()->getRepository(Entity\Users::class);

        return $repo->getUser($userId);
    }
182329
public function getUser(array $userData): UserInterface
    {
        if (gettype($userData[ self::FIELD_ID ]) === 'string') {
            $userData[ self::FIELD_ID ] = Uuid::fromString($userData[ self::FIELD_ID ]);
        }

        if (gettype($userData[ self::FIELD_EMAIL ]) === 'string') {
            $userData[ self::FIELD_EMAIL ] = new Email($userData[ self::FIELD_EMAIL ]);
        }

        if (isset($userData[ self::FIELD_LAST_LOGIN ]) === false) {
            $userData[ self::FIELD_LAST_LOGIN ] = 'now';
        }

        return new User(
            $userData[ self::FIELD_ID ],
            $userData[ self::FIELD_EMAIL ],
            $userData[ self::FIELD_NAME ],
            new DateTime($userData[ self::FIELD_BIRTHDAY ]),
            new DateTime($userData[ self::FIELD_LAST_LOGIN ])
        );
    }
695792
public function getUserEntityByIdentifier(string $userIdentifier): UserEntity
    {
        return new UserEntity(Member::get()->filter(['Email' => $userIdentifier])->first());
    }
427085
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
        global $USER;
        $requesterid = $requesterid ?: $USER->id;
        return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
            $requesterid);
    }
29694
public function deserialize($data, User $user, Section $section = null)
    {
        if (empty($section)) {
            $section = new Section();
            $section->refreshUuid();
            $section->setAuthor($user);
        }
        if ($data['activeContribution']) {
            $activeContribution = $this->contributionSerializer->deserialize($data['activeContribution'], $user, $section);
            $section->setActiveContribution($activeContribution);
        }

        return $section;
    }
125338
public function getByUserId( $userId ) {

		$modelClass	= self::$modelClass;

		$cart = $modelClass::findByParentIdParentType( $userId, CoreGlobal::TYPE_USER );

		if( !isset( $cart ) ) {

			$cart = $this->createByUserId( $userId );
		}

		return $cart;
	}
317368
public function deleteUser($userId)
    {
        // Forget remembered users.
        $this->userEntities = [];

        $query = $this->deleteUserQuery($userId);

        return $query->execute();
    }
658517
protected function getUser4Id($userId)
    {
        /** @var \PServerCore\Entity\Repository\User $userRepository */
        $userRepository = $this->entityManager->getRepository($this->collectionOptions->getEntityOptions()->getUser());

        return $userRepository->getUser4Id($userId);
    }