Check if a provider is already connected, return user record if available.

@param \Cake\Network\Request $request Request instance.
@return array|bool User array on success, false on failure.
13001
public function getUser(Request $request)
    {
        $this->_init($request);

        $providers = Hybrid_Auth::getConnectedProviders();
        foreach ($providers as $provider) {
            $adapter = Hybrid_Auth::getAdapter($provider);

            return $this->_getUser($adapter);
        }

        return false;
    }
991924
public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->credentials($request);

        if ($this->guard()->attempt($credentials, $request->has('remember'))) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if (! $lockedOut) {
            $this->incrementLoginAttempts($request);
        }

        return $this->sendFailedLoginResponse($request);
    }
1232514
protected function determineClientUserAgent($request)
    {
        $userAgent = null;
        $serverParams = $request->getServerParams();
        $userAgent = $serverParams['HTTP_USER_AGENT'];

        $checkProxyHeaders = $this->checkProxyHeaders;
        if ($checkProxyHeaders && !empty($this->trustedProxies)) {
            if (!in_array($userAgent, $this->trustedProxies)) {
                $checkProxyHeaders = false;
            }
        }

        if ($checkProxyHeaders) {
            foreach ($this->headersToInspect as $header) {
                if ($request->hasHeader($header)) {
                    $userAgent = trim(current(explode(',', $request->getHeaderLine($header))));
                    break;
                }
            }
        }
        return $userAgent;
    }
957001
public function twoStepVerification($request)
    {
        $user = Auth::User();

        if ($user) {
            $twoStepAuthStatus = $this->checkTwoStepAuthStatus($user->id);

            if ($twoStepAuthStatus->authStatus !== true) {
                return false;
            } else {
                if ($this->checkTimeSinceVerified($twoStepAuthStatus)) {
                    return false;
                }
            }

            return true;
        }

        return true;
    }
85580
public function getUser(ServerRequest $request)
    {
        $digest = $this->_getDigest($request);
        if (empty($digest)) {
            return false;
        }

        $user = $this->_findUser($digest['username']);
        if (empty($user)) {
            return false;
        }

        if (!$this->validNonce($digest['nonce'])) {
            return false;
        }

        $field = $this->_config['fields']['password'];
        $password = $user[$field];
        unset($user[$field]);

        $hash = $this->generateResponseHash($digest, $password, $request->getEnv('ORIGINAL_REQUEST_METHOD'));
        if (hash_equals($hash, $digest['response'])) {
            return $user;
        }

        return false;
    }
203848
public function getCurrentUserCollectionsAction(Request $request)
    {
        $ret = [
            "collections" => $this->listUserAuthorizedCollections($this->getAuthenticatedUser()),
        ];
        return Result::create($request, $ret)->createResponse();
    }
71847
public function getCurrentUserSubdefsAction(Request $request)
    {
        $ret = [
          "subdefs" => $this->listUserAuthorizedSubdefs($this->getAuthenticatedUser()),
        ];

        return Result::create($request, $ret)->createResponse();
    }
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;
    }
675559
public function getOAuthCallbackAction(Request $request)
    {
        $this->initSessionBag();

        if ($request->query->get("state") != $this->sessionBag->get("hash")) {
            throw new UserException("Invalid session verification hash");
        }

        $guzzle = new GuzzleClient();
        try {
            $response = $guzzle->post($this->getTokenUrl(), array("body" => array(
                "client_id" => $this->getClientId(),
                "client_secret" => $this->getClientSecret(),
                "grant_type" => $this->grantType,
                "redirect_uri" => $this->getCallbackUrl($request),
                "code" => $request->query->get("code")
            )));
        } catch (ClientException $e) {
            $errCode = $e->getResponse()->getStatusCode();
            if ($errCode == 400) {
                $desc = jsonDecode($e->getResponse()->getBody(true), true);
                $code = empty($desc["code"]) ? 0 : $desc["code"];
                $message = empty($desc["error_message"]) ? "Unknown error from API." : $desc["error_message"];

                throw new UserException(
                    "OAuth authentication failed[{$code}]: {$message}",
                    null,
                    [
                        'response' => $e->getResponse()->getBody()
                    ]
                );
            } else {
                throw $e;
            }
        }

        $responseData = jsonDecode($response->getBody(true));

        $this->storeOAuthData($responseData);
        return $this->returnResult($responseData);
    }
1264905
public function checkConnectionAction(Request $request, $name)
    {
        $ldapUser = $request->getSession()->get('LDAP_USER_ID');

        if (empty($ldapUser)) {
            $this->redirectToRoute('claro_ldap_login');
        }

        $selfRegistration = $this->platformConfigHandler->getParameter('allow_self_registration');
        $user = $this->get('claroline.manager.user_manager')->getUserByUsername($ldapUser);

        return [
            'selfRegistration' => $selfRegistration,
            'claroUser' => $user,
            'serverName' => $name,
        ];
    }
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;
    }
637118
protected function isFromTrustedProxy(Request $request)
    {
        $server = $request->getServerParams();
        if (!isset($server['REMOTE_ADDR'])) {
            return false;
        }
        return $this->ipIsTrustedProxy($server['REMOTE_ADDR']);
    }
451253
public function match(Request $request)
    {
        $routes = $this->get($request->getMethod());

        // First, we will see if we can find a matching route for this current request
        // method. If we can, great, we can just return it so that it can be called
        // by the consumer. Otherwise we will check for routes with another verb.

        if (! is_null($route = $this->fastCheck($routes, $request))) {
            // A route was found in the fast way.
        } else {
            $route = $this->check($routes, $request);
        }

        if (! is_null($route)) {
            return $route->bind($request);
        }

        // If no route was found, we will check if a matching route is specified on
        // another HTTP verb. If it is we will need to throw a MethodNotAllowed and
        // inform the user agent of which HTTP verb it should use for this route.

        $others = $this->checkForAlternateVerbs($request);

        if (! empty($others)) {
            return $this->getOtherMethodsRoute($request, $others);
        }

        throw new NotFoundHttpException;
    }
785541
public function exists($request)
    {
        // Hash a request data source into a string that returns cache metadata
        $this->key = $request['source'];

        if ($this->entries = $this->cache->fetch($this->key)) {
            return true;
        }
        return false;
    }
118315
public function requestAction(Request $request)
    {
        $form = $this
            ->createForm(new UserForgotPassType())
            ->handleRequest($request)
        ;

        $obj = $form->getData();

        $user = $this->getDoctrine()->getRepository('FOMUserBundle:User')->findOneByUsername($obj['search']);
        if ($user === null) {
            $user = $this->getDoctrine()->getRepository('FOMUserBundle:User')->findOneByEmail($obj['search']);
        }

        if (!$user) {
            $form->addError(new FormError($this->get("templating")->render(
                'FOMUserBundle:Password:request-error-nosuchuser.html.twig',
                array("search" => $obj))));
            return array('form' => $form->createView());
        } elseif ($user->getRegistrationToken()) {
            $form->addError(new FormError($this->get("templating")->render(
                'FOMUserBundle:Password:request-error-userinactive.html.twig', array("user" => $user))));
            return array(
                'user' => $user,
                'form' => $form->createView());
        }

        $this->setResetToken($user);

        return $this->redirect($this->generateUrl('fom_user_password_send'));
    }
1344887
public function postLogin(Request $request)
    {
        $this->validate($request, [
            $this->loginUsername() => 'required',
            'password'             => 'required',
        ]);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        $throttles = $this->isUsingThrottlesLoginsTrait();

        if ($throttles && $this->hasTooManyLoginAttempts($request)) {
            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->getCredentials($request);

        if (\Taki::attempt($credentials, $request->has('remember'))) {
            return $this->handleUserWasAuthenticated($request, $throttles);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }

        return redirect($this->loginPath())
                ->withInput($request->only($this->loginUsername(), 'remember'))
                ->withErrors([
                    $this->loginUsername() => $this->getFailedLoginMessage(),
        ]);
    }
492811
public function loadUsers(Request $request)
    {
        $restUsers = array();

        try {
            if ($request->query->has('roleId')) {
                $restUsers = $this->loadUsersAssignedToRole(
                    $this->requestParser->parseHref($request->query->get('roleId'), 'roleId')
                );
            } elseif ($request->query->has('remoteId')) {
                $restUsers = array(
                    $this->buildRestUserObject(
                        $this->userService->loadUser(
                            $this->contentService->loadContentInfoByRemoteId($request->query->get('remoteId'))->id,
                            Language::ALL
                        )
                    ),
                );
            } elseif ($request->query->has('login')) {
                $restUsers = array(
                    $this->buildRestUserObject(
                        $this->userService->loadUserByLogin($request->query->get('login'), Language::ALL)
                    ),
                );
            } elseif ($request->query->has('email')) {
                foreach ($this->userService->loadUsersByEmail($request->query->get('email'), Language::ALL) as $user) {
                    $restUsers[] = $this->buildRestUserObject($user);
                }
            }
        } catch (ApiExceptions\UnauthorizedException $e) {
            $restUsers = [];
        }

        if (empty($restUsers)) {
            throw new NotFoundException('No users were found with the given filter');
        }

        if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
            return new Values\UserList($restUsers, $request->getPathInfo());
        }

        return new Values\UserRefList($restUsers, $request->getPathInfo());
    }