コード例 #1
0
        public async Task PutAsync(HttpListenerContext context)
        {
            var data = await context.ReadPostDataAsync();

            if (data == null)
            {
                return;
            }

            var title       = data.GetOrDefault("title");
            var ingredients = data.GetOrDefault("ingredients");

            if (string.IsNullOrEmpty(title))
            {
                throw new HttpException(400, "Food is invalid");
            }

            if (!context.CheckCsrfToken(data.GetOrDefault("csrf-token")))
            {
                throw new HttpException(403, "Request is forged");
            }

            var food = await Foods.Add(title, ingredients);

            await context.WriteStringAsync(food.Id.ToString("N"));

            await callback(context.Request.Cookies.GetAuth() ?? "FoodBot", food).ConfigureAwait(false);
        }
コード例 #2
0
        private async Task <Dictionary <string, string> > CheckFormAsync(HttpListenerContext context)
        {
            var data = await context.ReadPostDataAsync();

            if (data == null)
            {
                throw new HttpException(400, "Login/pass required");
            }

            if (!context.CheckCsrfToken(data.GetOrDefault("csrf-token")))
            {
                throw new HttpException(403, "Request is forged");
            }

            return(data);
        }