Esempio n. 1
0
 public static RequestHandler GetRequestHandler(
     EndpointDefinition endpointDefinition,
     RequestDbConnection requestDbConnection,
     RequestParameterValues parameterValues)
 {
     return(new RequestHandler(endpointDefinition, requestDbConnection, parameterValues));
 }
Esempio n. 2
0
        private async Task HanldeLoginAsync(HttpContext context, ILogger logger)
        {
            try
            {
                var credentialData = await context.ReadModelAsync <Dictionary <string, string> >();

                var credentials = new Credentials(credentialData);

                using var requestDbConnection = RequestDbConnection.GetRequestDbConnection(EndpointConfiguration, credentials);
                var loginOk = await requestDbConnection.TestLoginAsync();

                if (loginOk)
                {
                    var tokens = credentials.Login(AuthConfig !);
                    await context.WriteResponseAsync(tokens, HttpStatusCode.OK);
                }
                else
                {
                    await context.WriteResponseAsync(new { Error = "Invalid Credentials" }, HttpStatusCode.Unauthorized);
                }
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
                await context.WriteErrorResponseAsync(e);
            }
        }
Esempio n. 3
0
 private RequestHandler(
     EndpointDefinition endpointDefinition,
     RequestDbConnection requestDbConnection,
     RequestParameterValues parameterValues)
 {
     _endpointDefinition  = endpointDefinition;
     _requestDbConnection = requestDbConnection;
     _parameterValues     = parameterValues;
 }
Esempio n. 4
0
        private async Task HandleRequestAsync(HttpContext context, EndpointDefinition endpointDefinition, ILogger logger)
        {
            try
            {
                var credentials     = AuthEnabled ? Credentials.Authenticate(context, AuthConfig !) : null;
                var parameterValues = RequestParameterValues.ResolveParameters(context, endpointDefinition);

                using var requestDbConnection = RequestDbConnection.GetRequestDbConnection(EndpointConfiguration, credentials);
                using var requestHandler      = RequestHandler.GetRequestHandler(endpointDefinition, requestDbConnection, parameterValues);

                var items = await requestHandler.HandleRequestAsync();

                await context.WriteResponseAsync(new { Items = items }, HttpStatusCode.OK);
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
                await context.WriteErrorResponseAsync(e);
            }
        }