returns the User Agent From $request or empty string if not found

@param array $request HTTP Request array (normally $_SERVER)
@return string
971403
public static function getUserAgent($request, $override_sideloaded_browser_ua = true)
    {
        if (!$override_sideloaded_browser_ua) {
            return $request['HTTP_USER_AGENT'];
        }

        if (isset($request[WURFL_Constants::UA])) {
            return $request[WURFL_Constants::UA];
        }
        
        foreach (self::$userAgentSearchOrder as $header) {
            if (isset($request[$header])) {
                return $request[$header];
            }
        }
        
        return '';
    }
1231943
public function handleRequest($request)
    {
        // recursion for batch
        if ($request->isBatch()) {
            $batch = array();
            foreach ($request->requests as $req) {
                $batch[] = $this->handleRequest($req);
            }
            $responses = implode(',',array_filter($batch, function($a){return $a !== null;}));
            if ($responses != null) {
                return "[{$responses}]";
            } else {
                return null;
            }
        }

        // check validity of request
        if ($request->checkValid()) {
            // check for method existence
            if (!$this->methodExists($request->method)) {
                $request->error_code = ERROR_METHOD_NOT_FOUND;
                $request->error_message = "Method not found.";
                return $request->toResponseJSON();
            }

            // try to call method with params
            try {
                $response = $this->invokeMethod($request->method, $request->params);
                if (!$request->isNotify()) {
                    $request->result = $response;
                } else {
                    return null;
                }
            // handle exceptions
            } catch (\Exception $e) {
                $request->error_code = ERROR_EXCEPTION;
                $request->error_message = $e->getMessage();
            }
        }

        // return whatever we got
        return $request->toResponseJSON();
    }
659910
public function handleRegister(array $request = [])
    {
        $validator = new \Valitron\Validator($request);
        $validator->rule('required', ['username', 'password', 'confirm_password']);
        $validator->rule(function ($field, $value, array $params, array $fields) {
            return is_string($value);
        }, ['username', 'password', 'confirm_password'])->message("{field} must be a string");
        $validator->rule('equals', 'confirm_password', 'password');
        $validator->rule('lengthBetween', 'username', 6, 200);
        $validator->rule('lengthBetween', 'password', 8, 80);
        if ($validator->validate() === false) {
            if (headers_sent() === false) {
                header('X-PHP-Response-Code: 422', true, 422);
            }
            return $this->templates->render("Auth::Register", [
                "messages" => [
                    'error' => $validator->errors(),
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "username" => $request['username']
            ]);
        }

        $response = $this->core->api('User/', 'POST')->run($request);
        if (headers_sent() === false) {
            foreach ($response["headers"] as $header) {
                header($header[0], $header[1], $header[2]);
            }
        }
        if ($response["headers"][0][2] === 422) {
            return $this->templates->render("Auth::Register", [
                "messages" => [
                    'error' => $response['response'],
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "username" => $request['username']
            ]);
        } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('login-page') . "?m=1");
            } else {
                return 'Redirect: ' . $this->router->generate('login-page') . "?m=1";
            }
        } else {
            return $this->templates->render("500", [
                "error" => $response['response'],
                "result" => ''
            ]);
        }
    }
1300847
public function getFieldsFromRequest(array $request)
    {
        $keys = isset($request['field']) ? $request['field'] : null;
        $fields = [];
        if (is_array($keys)) {
            foreach ($this->groups as $group) {
                foreach ($group->getFields() as $field) {
                    if (in_array($field->getKey(), $keys)) {
                        $field->loadDataFromRequest($request);
                        $fields[] = $field;
                    }
                }
            }
        }

        return $fields;
    }
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;
    }
1276654
protected function getRequestToken($request)
    {
        $name = $this->getName();
        $header = 'X-' . ucwords(strtolower($name));
        if ($token = $request->getHeader($header)) {
            return $token;
        }

        // Get from request var
        return $request->requestVar($name);
    }
1228455
public function beforeSend(Request $request)
    {
        //Host API isn't restful so path must always self::ENDPOINT_PATH
        $request->setUrl(self::ENDPOINT_PATH);

        $headers = array(
            self::CF_INTEGRATION_HEADER => $this->config->getValue('integrationName'),
            self::CF_INTEGRTATION_VERSION_HEADER => $this->config->getValue('version'),
        );
        $request->setHeaders($headers);

        $body = $request->getBody();
        $user_key_actions = array('zone_set', 'full_zone_set');
        if (in_array(strtolower($body['act']), $user_key_actions)) {
            $body['user_key'] = $this->data_store->getHostAPIUserKey();
        }
        $body['host_key'] = $this->integrationAPI->getHostAPIKey();
        $request->setBody($body);

        return $request;
    }
375446
public function byUsernameAction(Request $request)
   {
       $term = $request->get('username');
       $users = $this->get('asf_user.user.manager')->getRepository()->findByUsernameContains($term);
       $search = array();
       	
       foreach($users as $user) {
           $search[] = array(
               'id' => $user->getId(),
               'username' => $user->getUsername(),
               'email' => $user->getEmail()
           );
       }
       
       $response = new Response();
       $response->setContent(json_encode(array(
           'total_count' => count($search),
           'items' => $search
       )));
       
       return $response;
   }
994558
public function handleProfile(array $request = [])
    {
        if (empty($request['update']) === false) {
            if (isset($request['name']) === true && $request['name'] === '') {
                unset($request['name']);
            }
            if (isset($request['email']) === true && $request['email'] === '') {
                unset($request['email']);
            }
            if (isset($request['description']) === true && $request['description'] === '') {
                unset($request['description']);
            }
            if (isset($request['avatar']) === true && $request['avatar'] === '') {
                unset($request['avatar']);
            }

            $validator = new \Valitron\Validator($request);
            $validator->rule('optional', ['name', 'email', 'avatar', 'description']);
            $validator->rule(function ($field, $value, array $params, array $fields) {
                return is_string($value);
            }, ['name', 'description'])->message("{field} must be a string");
            $validator->rule('email', 'email');
            $validator->rule(function ($field, $value, array $params, array $fields) {
                return file_exists(rtrim(public_path(), '/') . $value) || (filter_var($value, FILTER_VALIDATE_URL) !== false);
            }, 'avatar')->message("{field} must be an external link or a local file path");
            if ($validator->validate() === false) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 422', true, 422);
                }
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => $validator->errors(),
                        'info' => '',
                        'success' => '',
                        'warning' => ''
                    ],
                    "details_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            }

            $response = $this->core->api('User/' . $this->core->auth()->details->id, 'PATCH')->run($request);
            if (headers_sent() === false) {
                foreach ($response["headers"] as $header) {
                    header($header[0], $header[1], $header[2]);
                }
            }
            if ($response["headers"][0][2] === 422) {
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => $response['response'],
                        'info' => '',
                        'success' => '',
                        'warning' => ''
                    ],
                    "details_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => '',
                        'info' => '',
                        'success' => 'Details changed successfully.',
                        'warning' => ''
                    ],
                    "details_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            } else {
                return $this->templates->render("500", [
                    "error" => $response['response'],
                    "result" => ''
                ]);
            }
        } elseif (empty($request['change']) === false) {
            $validator = new \Valitron\Validator($request);
            $validator->rule('required', ['password', 'confirm_password']);
            $validator->rule(function ($field, $value, array $params, array $fields) {
                return is_string($value);
            }, ['password', 'confirm_password'])->message("{field} must be a string");
            $validator->rule('equals', 'confirm_password', 'password');
            $validator->rule('lengthBetween', 'password', 8, 80);
            if ($validator->validate() === false) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 422', true, 422);
                }
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => $validator->errors(),
                        'info' => '',
                        'success' => '',
                        'warning' => ''
                    ],
                    "password_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            }

            $response = $this->core->api('User/password/' . $this->core->auth()->details->id, 'PATCH')->run($request);
            if (headers_sent() === false) {
                foreach ($response["headers"] as $header) {
                    header($header[0], $header[1], $header[2]);
                }
            }
            if ($response["headers"][0][2] === 422) {
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => $response['response'],
                        'info' => '',
                        'success' => '',
                        'warning' => ''
                    ],
                    "password_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => '',
                        'info' => '',
                        'success' => 'Password changed successfully.',
                        'warning' => ''
                    ],
                    "password_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            } else {
                return $this->templates->render("500", [
                    "error" => $response['response'],
                    "result" => ''
                ]);
            }
        } elseif (empty($request['delete']) === false) {
            $response = $this->core->api('User/' . $this->core->auth()->details->id, 'DELETE')->run([]);
            if (headers_sent() === false) {
                foreach ($response["headers"] as $header) {
                    header($header[0], $header[1], $header[2]);
                }
            }
            if ($response["headers"][0][2] === 422) {
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => $response['response'],
                        'info' => '',
                        'success' => '',
                        'warning' => ''
                    ],
                    "details_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
                $this->core->auth()->invalidate();
                $this->router->map('GET', '/login', "Auth@showLogin", 'login-page');
                if (isset($_GET['template']) === false) {
                    return redirect($this->router->generate('login-page') . "?m=5");
                } else {
                    return 'Redirect: ' . $this->router->generate('login-page') . "?m=5";
                }
            } else {
                return $this->templates->render("500", [
                    "error" => $response['response'],
                    "result" => ''
                ]);
            }
        } elseif (empty($request['invalidate']) === false) {
            $response = $this->core->api('User/sessions/' . $this->core->auth()->details->id, 'DELETE')->run([]);
            if (headers_sent() === false) {
                foreach ($response["headers"] as $header) {
                    header($header[0], $header[1], $header[2]);
                }
            }
            if ($response["headers"][0][2] === 422) {
                return $this->templates->render("Main::Dashboard", [
                    "messages" => [
                        'error' => $response['response'],
                        'info' => '',
                        'success' => '',
                        'warning' => ''
                    ],
                    "details_form" => true,
                    "user" => $this->core->auth()->details
                ]);
            } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
                $this->core->auth()->invalidate();
                $this->router->map('GET', '/login', "Auth@showLogin", 'login-page');
                if (isset($_GET['template']) === false) {
                    return redirect($this->router->generate('login-page') . "?m=6");
                } else {
                    return 'Redirect: ' . $this->router->generate('login-page') . "?m=6";
                }
            } else {
                return $this->templates->render("500", [
                    "error" => $response['response'],
                    "result" => ''
                ]);
            }
        } else {
            throw new \Exception('Invalid action performed');
        }
    }
982784
public function getPayload($request = null)
    {
        if (!$request) {
            return $this->_payload;
        }

        $payload = null;

        $token = $this->getToken($request);
        if ($token) {
            $payload = $this->_decode($token);
        }

        return $this->_payload = $payload;
    }
756423
protected function _basic($request) {
		$users = $this->_config['users'];
		$username = $request->env('PHP_AUTH_USER');
		$auth = $this->_classes['auth'];
		$basic = $auth::encode($username, $request->env('PHP_AUTH_PW'));
		$encoded = ['response' => null];

		if (isset($users[$username])) {
			$encoded = $auth::encode($username, $users[$username]);
		}
		if ($basic['response'] !== $encoded['response']) {
			$this->_writeHeader("WWW-Authenticate: Basic realm=\"{$this->_config['realm']}\"");
			return;
		}
		return compact('username', 'password');
	}
484157
public function getRequestUserGroups($request) {

        // user id of the user trying to log in
        $user_id = $this->user->where('email', '=', $this->getRequestEmail($request) )->get()->first()->id;

        // the user's user groups (actually, the records as a GROUP (model) object
        $user_groups = $this->user->find($user_id)->group;

        // create an array
        $usergroupArray = [];
        foreach ($user_groups as $user_group) {
            $usergroupArray[] = $user_group->title;
        }

        return $usergroupArray;
    }
291419
private function processRequest($request)
    {
        if (!is_array($request)) {
            return self::requestError();
        }

        // The presence of the 'id' key indicates that a response is expected
        $isQuery = array_key_exists('id', $request);

        $id = &$request['id'];

        if (($id !== null) && !is_int($id) && !is_float($id) && !is_string($id)) {
            return self::requestError();
        }

        $version = &$request['jsonrpc'];

        if ($version !== self::VERSION) {
            return self::requestError($id);
        }

        $method = &$request['method'];

        if (!is_string($method)) {
            return self::requestError($id);
        }

        // The 'params' key is optional, but must be non-null when provided
        if (array_key_exists('params', $request)) {
            $arguments = $request['params'];

            if (!is_array($arguments)) {
                return self::requestError($id);
            }
        } else {
            $arguments = array();
        }

        if ($isQuery) {
            return $this->processQuery($id, $method, $arguments);
        }

        $this->processNotification($method, $arguments);
        return null;
    }
561800
public function filter($request): array
    {
        if (\is_array($request)) {
            return $request;
        } elseif ($request === '*') {
            return $this->get();
        } elseif ($request[0] === '!') {
            return \array_diff($this->get(), [\substr($request, 1)]);
        }

        return [$request];
    }
1152266
public function isAction($request = null)
    {
        $is_action = false;
        if ($this->isSingle()) {
            $queryString = $request ? $request->getQueryString() : Lb::app()->getQueryString();
            $requestUri = $request ? $request->getUri() : Lb::app()->getUri();
            if (Lb::app()->isPrettyUrl()) {
                $requestUri = str_replace('?' . $queryString, '', $requestUri);
                if (!trim($requestUri, '/') || stripos($requestUri, '/action/') !== false) {
                    $is_action = true;
                }
            } else {
                if (!trim($requestUri, '/') || stripos($queryString, 'action=') !== false) {
                    $is_action = true;
                }
            }
        }
        return $is_action;
    }
118201
public function showLogin(array $request = [])
    {
        $messages = [
            'error' => '',
            'info' => '',
            'success' => '',
            'warning' => ''
        ];
        if (empty($request['m']) === false) {
            if ($request['m'] == 1) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['info'] = 'Please activate your account through the confirmation email sent.';
                $messages['success'] = 'User registered successfully.';
            } elseif ($request['m'] == 2) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['info'] = 'Password reset email sent to account. Please reset your password through the link in the email.';
            } elseif ($request['m'] == 3) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 422', true, 422);
                }
                $messages['error'] = 'Invalid password reset link.';
            } elseif ($request['m'] == 4) {
                $messages['success'] = 'Password reset successfully.';
            } elseif ($request['m'] == 5) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['success'] = 'Account deleted successfully.';
            } elseif ($request['m'] == 6) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['success'] = 'Account sessions invalidated successfully.';
            }
        }
        return $this->templates->render("Auth::Login", [
            "messages" => $messages,
            "username" => ''
        ]);
    }
207624
public function getUser(ServerRequest $request)
    {
        $username = $request->getEnv('PHP_AUTH_USER');
        $pass = $request->getEnv('PHP_AUTH_PW');

        if (!is_string($username) || $username === '' || !is_string($pass) || $pass === '') {
            return false;
        }

        return $this->_findUser($username, $pass);
    }