public async Task create([QueryField] string username, [QueryField] string password)
        {
            if (username == null || password == null)
            {
                throw HttpException.BadRequest();
            }

            if (!validated)
            {
                throw HttpException.Forbidden();
            }

            // If a user already exists, it is not possible to create a new user
            if (await getUser(username) != null)
            {
                throw HttpException.NotAcceptable();
            }

            var model = new AccountModel {
                username    = username.ToLower(), // :to_lower_thinking: - Taylor
                permissions = new List <string> {
                    "Admin"
                }
            };

            model.setPassword(password);

            await accountCollection.InsertOneAsync(model);
        }
Example #2
0
        private async static Task Offer(IHttpContext context)
        {
            var offer = await context.GetRequestDataAsync <RTCSessionDescriptionInit>();

            var jsonOptions = new JsonSerializerOptions();

            jsonOptions.Converters.Add(new JsonStringEnumConverter());

            var pc = await CreatePeerConnection();

            var result = pc.setRemoteDescription(offer);

            if (result == SetDescriptionResultEnum.OK)
            {
                var answer = pc.createAnswer(null);
                await pc.setLocalDescription(answer);

                context.Response.ContentType = "application/json";
                using (var responseStm = context.OpenResponseStream(false, false))
                {
                    await JsonSerializer.SerializeAsync(responseStm, answer, jsonOptions);
                }
            }
            else
            {
                throw HttpException.NotAcceptable($"Error setting SDP offer {result}.");
            }
        }
        protected override async Task OnRequestAsync(IHttpContext context)
        {
            Boolean result = false;

            log.LogDebug("[OnRequestAsync] RequestedPath:[{0}] - HttpVerb:[{1}]", context.Request.Url.AbsolutePath, context.Request.HttpVerb);

            if (context.Request.Headers["Content-Type"] == "application/json")
            {
                String body = await context.GetRequestBodyAsStringAsync();

                result = s2sEventPipe.ParseCallbackContent(context.Request.HttpVerb.ToString(), context.Request.Url.AbsolutePath, body);
            }

            if (!result)
            {
                throw HttpException.NotAcceptable();
            }
        }