@param Request $request

@return UserInterface
@throws BadUserCredentialsHttpException
161590
protected function getUser(Request $request)
    {
        // find the user
        $user = $this->userRepository->findOneByUsername($request->headers->get('username'));
        if (!$user) {
            throw new BadUserCredentialsHttpException();
        }

        // Check the validity of the password
        $encoder = $this->encoderFactory->getEncoder($user);
        if (!$encoder->isPasswordValid($user->getPassword(), $request->headers->get('password'), $user->getSalt())) {
            throw new BadUserCredentialsHttpException();
        }

        return $user;
    }
1064596
public function reset(Request $request)
    {
        $data = new PasswordResetData();

        $form = $this->form(new PasswordResetForm($data));
        $form->handleRequest($request);

        if ($form->isNotValid()) {
            return back()->withErrors($form->errors()->all());
        }

        $response = $this->broker()->reset(
            $this->credentials($data),
            function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        return $response == Password::PASSWORD_RESET
            ? $this->sendResetResponse($request, $response)
            : $this->sendResetFailedResponse($request, $response);
    }
734958
public function authentication(Request $request, array $credentials)
    {
        if (isset($credentials['username'], $credentials['password'])) {
            $value = $this->_generateHeader($credentials['username'], $credentials['password']);
            $request = $request->withHeader('Authorization', $value);
        }

        return $request;
    }
823912
public function createAction(Request $request)
        {
            $oUser = new User();
            $form = $this->createCreateForm($oUser);
            $form->handleRequest($request);

            if ($form->isValid()) {

                $factory  = $this->get('security.encoder_factory');
                $encoder  = $factory->getEncoder($oUser);
                $password = $encoder->encodePassword($oUser->getPassword(), $oUser->getSalt());
                $oUser->setPassword($password);
                $oUser->save();

                return $this->redirect($this->generateUrl('backend_system_user'));
            }

            return $this->render('SlashworksBackendBundle:User:new.html.twig', array(
                'entity' => $oUser,
                'form'   => $form->createView(),
            ));
        }
1196318
public function password(Request $request)
    {
        $user = $request->user();

        if ($user) {
            return view('user.password')
            ->with('user', $user);
        }

        return back()->withErrors(['Could not find user']);
    }
490790
private function getUserAgent(Request $request)
    {
        if (!$this->userAgent) {
            $this->userAgent = $request->headers->get('User-Agent');
        }

        return $this->userAgent;
    }
663536
public function execute(RequestInterface $request): RequestInterface
    {
        if (is_null($this->sessionToken)) {
            return $request;
        } else {
            return $request->withHeader(
                self::HEADER_CLIENT_AUTHENTICATION,
                [$this->sessionToken->getToken()]
            );
        }
    }
1006739
public function create(Request $request)
    {
        app('soda.interface')->setHeading('New User');
        app('soda.interface')->breadcrumbs()->addLink(route('soda.users.index'), 'Users');

        try {
            $user = $this->users->newInstance($request);
            $roleIds = $this->users->getRoles();
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'user']));
        }

        return soda_cms_view('data.users.view', compact('user', 'roleIds'));
    }
1031176
protected function authenticateUser(Request $request, UserInterface $user, $resourceOwnerName, $accessToken, $fakeLogin = true)
    {
        try {
            $this->container->get('hwi_oauth.user_checker')->checkPreAuth($user);
            $this->container->get('hwi_oauth.user_checker')->checkPostAuth($user);
        } catch (AccountStatusException $e) {
            // Don't authenticate locked, disabled or expired users
            return;
        }

        $token = new OAuthToken($accessToken, $user->getRoles());
        $token->setResourceOwnerName($resourceOwnerName);
        $token->setUser($user);
        $token->setAuthenticated(true);

        $this->get('security.token_storage')->setToken($token);

        if ($fakeLogin) {
            // Since we're "faking" normal login, we need to throw our INTERACTIVE_LOGIN event manually
            $this->container->get('event_dispatcher')->dispatch(
                SecurityEvents::INTERACTIVE_LOGIN,
                new InteractiveLoginEvent($request, $token)
            );
        }
    }
81640
public function saveUserPref(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            $this->app->abort(400);
        }

        $msg = $this->app->trans('Error while saving preference');
        $prop = $request->request->get('prop');
        $value = $request->request->get('value');

        $success = false;
        if (null !== $prop && null !== $value) {
            $this->getUserManipulator()->setUserSetting($this->getAuthenticatedUser(), $prop, $value);
            $success = true;
            $msg = $this->app->trans('Preference saved !');
        }

        return new JsonResponse(['success' => $success, 'message' => $msg]);
    }
794194
protected function getInvitedUser(Request $request)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $user = User::where('email', $request->email)
            ->first();
        if (!empty($user)) {
            return $this->validateUser($user, $this->userContext()->team_id);
        }
        $user = new User();
        $user->email = $request->email;
        $user->name = $request->has('name') ? $request->name : $request->email;
        $user->password = bcrypt(md5(microtime()));
        $user->save();
        return $user;
    }
393331
public function getUser(ServerRequestInterface $request)
    {
        $server = $request->getServerParams();
        if (!isset($server['PHP_AUTH_USER']) || !isset($server['PHP_AUTH_PW'])) {
            return null;
        }

        $username = $server['PHP_AUTH_USER'];
        $password = $server['PHP_AUTH_PW'];

        if (!is_string($username) || $username === '' || !is_string($password) || $password === '') {
            return null;
        }

        return $this->_identifier->identify([
            IdentifierInterface::CREDENTIAL_USERNAME => $username,
            IdentifierInterface::CREDENTIAL_PASSWORD => $password,
        ]);
    }
592678
private function requireAuthentication(Request $request): Administrator
    {
        $administrator = $this->authentication->authenticateByApiKey($request);
        if ($administrator === null) {
            throw new AccessDeniedHttpException(
                'No valid session key was provided as basic auth password.',
                null,
                1512749701
            );
        }

        return $administrator;
    }
875742
public function addAdmins(Request $request)
    {
        $admins = $request->request->get('admins', []);

        // Remove empty values
        $admins = array_filter($admins);

        if (!is_array($admins) || count($admins) === 0) {
            $this->app->abort(400, '"admins" parameter must contains at least one value.');
        }
        /** @var Authenticator $authenticator */
        $authenticator = $this->app->getAuthenticator();
        if (!in_array($authenticator->getUser()->getId(), $admins)) {
            $admins[] = $authenticator->getUser()->getId();
        }

        $userRepository = $this->getUserRepository();

        $demotedAdmins = [];

        foreach ($userRepository->findAdmins() as $admin) {
            if (!in_array($admin->getId(), $admins)) {
                $demotedAdmins[$admin->getId()] = $admin;
            }
        }

        $userRepository->findBy(['id' => $admins]);
        $admins = array_map(function ($usrId) use ($userRepository) {
            if (null === $user = $userRepository->find($usrId)) {
                throw new RuntimeException(sprintf('Invalid usrId %s provided.', $usrId));
            }

            return $user;
        }, $admins);

        /** @var UserManipulator $userManipulator */
        $userManipulator = $this->app['manipulator.user'];

        $userManipulator->demote($demotedAdmins);
        $userManipulator->promote($admins);

        /** @var ACLManipulator $aclManipulator */
        $aclManipulator = $this->app['manipulator.acl'];
        $aclManipulator->resetAdminRights($admins);

        return $this->app->redirectPath('admin_dashboard');
    }
557522
public function resetPasswordAction(Request $request)
    {
        if ($this->getUser()) {
            return $this->redirectToRoute($this->get(Configuration::class)->getHomeRoute());
        }
        $token = $request->query->get('token');
        if (!$token) {
            return $this->redirectToRoute('lost_password');
        }

        $userManager = $this->get(UserManagerInterface::class);
        $user = $userManager->loadUserByToken($token);
        if (!$user) {
            $this->addFlash(
                'error',
                $this->get('translator')->trans('reset_password.token_not_found', [], 'security')
            );

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

        $form = $this->createForm(ResetUserPasswordType::class);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $password = $form->get('password')->getData();
            $userManager->setPlainTextPassword($user, $password);
            $userManager->save($user);

            $authenticationManager = $this->get('security.authentication.manager');
            $token = $authenticationManager->authenticate(
                new UsernamePasswordToken($user, $password, 'main', $user->getRoles())
            );
            $tokenStorage = $this->get('security.token_storage');
            $tokenStorage->setToken($token);

            return $this->redirectToRoute($this->get(Configuration::class)->getHomeRoute());
        }

        return [
            'user' => $user,
            'form' => $form->createView(),
        ];
    }
46477
public function setRequestUser (Request $request)
    {
        $request->addUserCallback ('accounts', function (Request $request) {

            $userid = $request->getSession ()->get ('catlab-user-id');

            if ($userid)
            {
                $user = MapperFactory::getUserMapper ()->getFromId ($userid);
                if ($user)
                    return $user;
            }

            return null;
        });
    }
427349
public function login(Request $request)
    {
        $data = $request->getParsedBody();
        $this->checkingRequirements($data);

        /** @var UserPasswordInterface $user */
        if (null === $user = $this->findByUsername($data['username'])) {
            $this->logger->warning(
                'security.authentication.form: user not found with criteria {criteria}',
                ['criteria' => $this->getCriteriaAsSting(['username' => $data['username']])]
            );

            throw UserNotFoundException::create(['username' => $data['username']]);
        }

        if (!$this->passwordManager->verify($data['password'], $user->getPassword())) {
            $this->logger->warning(
                'security.authentication.form: invalid password for user with criteria {criteria}',
                ['criteria' => $this->getCriteriaAsSting(['username' => $data['username']])]
            );

            throw InvalidPasswordException::create(['username' => $data['username']]);
        }

        $this->logger->info(
            'security.authentication.form: login successful for user with id {id}', ['id' => $user->getId()]
        );

        $this->session->set($request, self::USER_KEY, $user->getId());
    }