@param \eZ\Publish\API\Repository\Values\User\User $user
@param \Symfony\Component\HttpFoundation\Request $request

@return \eZ\Publish\Core\REST\Server\Values\Version
12318
private function mapUserToVersion(User $user, Request $request)
    {
        $content = $this->repository->getContentService()->loadContent($user->id);
        $request->headers->set('Url', $request->getPathInfo());

        return new Version(
            $content,
            $this->repository->getContentTypeService()->loadContentType($content->contentInfo->contentTypeId),
            $this->repository->getContentService()->loadRelations($content->getVersionInfo()),
            $request->getPathInfo()
        );
    }
1025861
public function changePassword(User $user, Request $request)
    {
        $user->password = Hash::make($request->get('password'));
        $user->save();

        Alert::info(__('User was saved'));

        return back();
    }
469416
public function resultForUser($user, Request $request)
    {

        $repos = new ResultsRepository();
        $results = $repos->getByUser(
            $user,
            $request->input('monthsBack', false),
            $request->input('fromMonthsBack', false)
        );

        return view('game-of-tests::results.author', ['results' => $results]);
    }
130291
public function postAuthProcess(Request $request, User $user)
    {
        $date = new \DateTime('+' . (int) $this->getConf()->get(['registry', 'actions', 'validation-reminder-days']) . ' days');
        $manager = $this->getEntityManager();

        foreach ($this->getValidationParticipantRepository()->findNotConfirmedAndNotRemindedParticipantsByExpireDate($date) as $participant) {
            $validationSession = $participant->getSession();
            $basket = $validationSession->getBasket();

            if (null === $token = $this->getTokenRepository()->findValidationToken($basket, $participant->getUser())) {
                continue;
            }

            $url = $this->app->url('lightbox_validation', ['basket' => $basket->getId(), 'LOG' => $token->getValue()]);
            $this->dispatch(PhraseaEvents::VALIDATION_REMINDER, new ValidationEvent($participant, $basket, $url));

            $participant->setReminded(new \DateTime('now'));
            $manager->persist($participant);
        }

        $manager->flush();

        $session = $this->getAuthenticator()->openAccount($user);

        if ($user->getLocale() != $this->app['locale']) {
            $user->setLocale($this->app['locale']);
        }

        $width = $height = null;
        if ($request->cookies->has('screen')) {
            $data = array_filter((explode('x', $request->cookies->get('screen', ''))));
            if (count($data) === 2) {
                $width = $data[0];
                $height = $data[1];
            }
        }
        $session->setIpAddress($request->getClientIp())
            ->setScreenHeight($height)
            ->setScreenWidth($width);

        $manager->persist($session);
        $manager->flush();

        return $session;
    }
1153624
public function update(UserRequest $request, User $user)
    {
        $user->update($request->all());
        $this->_syncUserGroups($user, $request->get('user_group_id'));
        return redirect()->route('admin.user.index');
    }
1104154
public function update(User $user, FormRequest $request)
    {
        $data = $request->all();

        $userData = Arr::except($data, ['exit', 'permissions', 'roles', 'password_confirmation']);

        if (!isset($userData['password']) || $userData['password'] === '') {
            $userData = Arr::except($userData, 'password');
        } else {
            $userData['password'] = Hash::make($data['password']);
        }

        $roles = $data['roles'] ?? [];
        $permissions = $data['permissions'] ?? [];
        $user->roles()->sync($roles);
        $user->syncPermissions($permissions);

        $this->repository->update($user->id, $userData);

        return $this->redirect($request, $user);
    }
926779
public function assignUserToUserGroup($userId, Request $request)
    {
        $user = $this->userService->loadUser($userId);

        try {
            $userGroupLocation = $this->locationService->loadLocation(
                $this->extractLocationIdFromPath($request->query->get('group'))
            );
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        try {
            $userGroup = $this->userService->loadUserGroup(
                $userGroupLocation->contentId
            );
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        try {
            $this->userService->assignUserToUserGroup($user, $userGroup);
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        $userGroups = $this->userService->loadUserGroupsOfUser($user);
        $restUserGroups = array();
        foreach ($userGroups as $userGroup) {
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);

            $restUserGroups[] = new Values\RestUserGroup(
                $userGroup,
                $contentType,
                $userGroupContentInfo,
                $userGroupLocation,
                $this->contentService->loadRelations($userGroup->getVersionInfo())
            );
        }

        return new Values\UserGroupRefList(
            $restUserGroups,
            $this->router->generate(
                'ezpublish_rest_loadUserGroupsOfUser',
                array('userId' => $userId)
            ),
            $userId
        );
    }
1312122
public function byInvitationAction(Request $request, $userClass)
    {
        $invitationToken = $request->query->get('token');
        try {
            // we need to know if the invitation token given exists in
            // database, in case that it isn't, it throws 404.
            $user = $this->get('bengor_user.' . $userClass . '.by_invitation_token_query')->__invoke(
                new UserOfInvitationTokenQuery($invitationToken)
            );
        } catch (UserDoesNotExistException $exception) {
            return new JsonResponse(null, 404);
        } catch (UserTokenExpiredException $exception) {
            return new JsonResponse(null, 404);
        } catch (\InvalidArgumentException $exception) {
            return new JsonResponse(null, 404);
        }

        $form = $this->get('form.factory')->createNamedBuilder('', SignUpByInvitationType::class, null, [
            'roles'            => $this->getParameter('bengor_user.' . $userClass . '_default_roles'),
            'invitation_token' => $invitationToken,
            'csrf_protection'  => false,
        ])->getForm();

        $form->handleRequest($request);
        if ($form->isValid()) {
            $commandBus = $this->get('bengor_user.' . $userClass . '.api_command_bus');

            try {
                $commandBus->handle(
                    $form->getData()
                );
                $commandBus->handle(
                    new LogInUserCommand(
                        $user['email'],
                        $form->getData()->password()
                    )
                );
            } catch (UserDoesNotExistException $exception) {
                return new JsonResponse(null, 404);
            } catch (UserInactiveException $exception) {
                return new JsonResponse(null, 404);
            } catch (UserPasswordInvalidException $exception) {
                return new JsonResponse('Bad credentials', 400);
            } catch (UserAlreadyExistException $exception) {
                return new JsonResponse('Bad credentials', 400);
            }
            $token = $this->get('lexik_jwt_authentication.encoder.default')->encode(['email' => $user['email']]);

            return new JsonResponse(['token' => $token]);
        }

        return new JsonResponse(FormErrorSerializer::errors($form), 400);
    }
537635
public function createAction(Request $request)
    {
        $user = $this->getParameter('opifer_cms.user_model');
        $user = new $user();

        $form = $this->createForm(UserFormType::class, $user);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $this->get('fos_user.user_manager')->updateUser($user, true);

            $this->addFlash('success', $this->get('translator')->trans('user.new.success', [
                '%username%' => ucfirst($user->getUsername()),
                '%id%' => $user->getId(),
            ]));

            return $this->redirectToRoute('opifer_cms_user_index');
        }

        return $this->render('OpiferCmsBundle:Backend/User:create.html.twig', [
            'form' => $form->createView(),
        ]);
    }
1325857
public function deleteBulkAction(Request $request, User $user)
    {
        $errors = [];

        $data = $this->decodeRequestData($request);
        if (empty($data) || !is_array($data)) {
            // Invalid or empty JSON data received
            $errors[] = [
                'path' => '',
                'message' => 'Invalid JSON data',
            ];
        } else {
            try {
                $this->manager->deleteBulk(json_decode($request->getContent(), true), $user);
            } catch (\Exception $e) {
                return new JsonResponse($e->getMessage(), 422);
            }
        }

        return new JsonResponse(null, 204);
    }
1344725
public function update(User $user, Request $request)
    {
        // user we want to edit and session user must be the same
        if ($user->id != user()->id) {
            return redirect()
                ->back()
                ->withInput($request->all())
                ->withErrors(['firstname' => 'Unauthorized access']);
        }

        // submit without a file
        if (is_null($request->file('photo'))) {
            $this->validate($request, array_except(User::$rulesProfile, 'photo'));
        }
        else {
            $this->validate($request, User::$rulesProfile);

            $photo = $this->uploadProfilePicture($request->file('photo'));

            $request->merge(['image' => $photo]);
        }

        // update user without photo and password
        $this->updateEntry($user, $request->only([
            'firstname',
            'lastname',
            'cellphone',
            'telephone',
            'born_at',
            'image'
        ]));

        // update user  password
        if ($request['password'] && strlen($request['password']) >= 2) {
            user()->update([
                'password' => bcrypt($request['password']),
            ]);
        }

        return redirect('/admin/profile');
    }
324267
public function run(Request $request) {
		$page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
		$page->setTitle($this->getServiceContainer()->getTranslator()->trans('profile'));

		$payload = new Blank();
		if ($request->isMethod('POST')) {
			$post = $request->request;
			$user = $this->getServiceContainer()->getAuthManager()->getUser();
			$domain = new UserDomain($this->getServiceContainer());
			$serializer = User::getSerializer();

			$fields = $serializer->getFields();
			$fields[] = 'display_name_user_select';
			$attribs = [];

			foreach ($fields as $field) {
				if ($post->has($field)) {
					$attribs[$field] = $post->get($field);
				}
			}

			$payload = $domain->update($user->getId(), ['attributes' => $attribs]);
		}
		return $this->responder->run($request, $payload);
	}
610844
public function save(Request $request, UserInterface $user)
    {
        $eid = $request->get('eid');
        $language = $request->get('language');
        $tid = $request->get('tid');
        $teaserId = $request->get('teaser_id');
        $isPublish = $request->get('isPublish');
        $values = $request->get('values');
        $publishComment = $request->get('publishComment');

        if ($values) {
            $values = json_decode($values, true);
        }

        $element = $this->elementService->findElement($eid);
        $elementtype = $this->elementService->findElementtype($element);
        $elementtypeStructure = $elementtype->getStructure();

        $oldElementVersion = $this->elementService->findLatestElementVersion($element);
        $oldElementStructure = $this->elementService->findElementStructure($oldElementVersion, 'de');
        $oldVersion = $oldElementVersion->getVersion();
        $isMaster = $element->getMasterLanguage() === $language;

        $tree = $this->treeManager->getByNodeId($tid);
        $node = $tree->get($tid);

        $teaser = null;
        if ($teaserId) {
            $teaser = $this->teaserManager->find($teaserId);
        }

        $comment = null;
        if ($request->get('comment')) {
            $comment = $request->get('comment');
        }

        if ($language === $element->getMasterLanguage()) {
            $elementStructure = new ElementStructure();
            if ($oldElementStructure->getDataId()) {
                $elementStructure
                    ->setDataId($oldElementStructure->getDataId())
                    ->setDsId($oldElementStructure->getDsId())
                    ->setType('root')
                    ->setName($oldElementStructure->getName());
            } else {
                $elementStructure
                    ->setDataId(UuidUtil::generate())
                    ->setDsId($elementtypeStructure->getRootDsId())
                    ->setType('root')
                    ->setName($elementtypeStructure->getRootNode()->getName());
            }
            $map = $this->applyStructure($elementStructure, $elementtypeStructure, $values, $language, $oldElementStructure);
            $this->applyOldValues($elementStructure, $oldElementStructure, $elementtypeStructure, $language);
            $this->applyValues($elementStructure, $elementtypeStructure, $values, $language, $map, null);
        } else {
            $elementStructure = clone $oldElementStructure;
            $this->applyValues($elementStructure, $elementtypeStructure, $values, $language, null, $element->getMasterLanguage());
        }

        $elementStructure->setId(null);

        $rii = new \RecursiveIteratorIterator($elementStructure->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $structure) {
            /* @var $structure ElementStructure */
            $structure->setId(null);
        }

        $elementVersion = $this->elementService->createElementVersion($element, $elementStructure, $language, $user->getId(), $comment);

        if ($teaser) {
            $this->saveTeaserData($teaser, $language, $request);
        } else {
            $this->saveNodeData($node, $language, $request);
        }

        // TODO: available languages
        $this->saveMeta($elementVersion, $language, $isMaster, ['de'], $request);

        $event = new SaveElementEvent($element, $language, $oldVersion);
        $this->eventDispatcher->dispatch(ElementEvents::SAVE_ELEMENT, $event);

        $publishSlaves = [];
        if ($isPublish) {
            $publishSlaves = $this->checkPublishSlaves($elementVersion, $node, $teaser, $language);
            if ($teaser) {
                $this->publishTeaser($elementVersion, $teaser, $language, $user->getId(), $publishComment, $publishSlaves);
            } else {
                $this->publishTreeNode($elementVersion, $node, $language, $user->getId(), $publishComment, $publishSlaves);
            }
        }

        $status = '';
        if ($teaser) {
            if ($this->teaserManager->isPublished($teaser, $language)) {
                $status = $this->teaserManager->isAsync($teaser, $language) ? 'async' : 'online';
            }
        } else {
            if ($tree->isPublished($node, $language)) {
                $status = $tree->isAsync($node, $language) ? 'async' : 'online';
            }
        }

        return [$elementVersion, $node, $teaser, $publishSlaves, $status];
    }
1064962
public function isCacheable(Request $request, $user)
    {
        if (!$this->active) {
            return false;
        }

        if ($user) {
            return false;
        }

        if ($request->hasSession() && $request->getSession()->get('no_cache', false)) {
            $request->getSession()->remove('no_cache');

            return false;
        }

        if ($this->env != 'prod') {
            return false;
        }

        if ($request->getMethod() != 'GET') {
            return false;
        }

        return true;
    }
38196
public function saveUser(User $user, Request $request)
    {
        $user->fill($request->get('user'))
            ->save();

        Alert::info(__('User was saved.'));

        return back();
    }
420448
protected function registered(Request $request, $user)
    {
        $survUser = User::find($user->id);
        $log = new SLUsersActivity;
        $log->UserActUser = $survUser->id;
        $adminRoleID = 15; // but let's double-check this system
        $admDef = SLDefinitions::where('DefDatabase', 1)
            ->where('DefSet', 'User Roles')
            ->where('DefSubset', 'administrator')
            ->first();
        if ($admDef && isset($admDef->DefID)) {
            $adminRoleID = $admDef->DefID;
        }
        $hasAdmins = SLUsersRoles::where('RoleUserRID', $adminRoleID) // role id of 'administrator'
            ->get();
        if ($hasAdmins->isEmpty()) {
            $survUser->assignRole('administrator');
            $log->UserActCurrPage = 'NEW SYSTEM ADMINISTRATOR!';
        } elseif ($request->has('newVolunteer') && intVal($request->newVolunteer) == 1) {
            $survUser->assignRole('volunteer');
            $log->UserActCurrPage = 'NEW VOLUNTEER!';
        }
        $log->save();
        $domainPath = '';
        $appUrl = SLDefinitions::where('DefDatabase', 1)
            ->where('DefSet', 'System Settings')
            ->where('DefSubset', 'app-url')
            ->first();
        if ($appUrl && isset($appUrl->DefDescription)) {
            $domainPath = $appUrl->DefDescription;
        }
        if ($request->has('previous') && trim($request->get('previous')) != '') {
            session()->put('redirLoginSurvey', time());
            session()->put('previousUrl', trim($request->get('previous')));
        }
        return redirect($domainPath . '/afterLogin');
    }
458717
public function update(UpdateUserRequest $request, User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        $user->update($request->getValidatedData());
        $user->roles()->sync($request->get('roles'));

        $this->transNotification('updated', ['name' => $user->full_name], $user->toArray());

        return redirect()->route('admin::auth.users.show', [$user->hashed_id]);
    }