Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context)
        {
            if (options.RequestConstrainAsync != null)
            {
                if (!await options.RequestConstrainAsync(context))
                {
                    return;
                }
            }

            var query = context.Request.QueryString;
            var model = query.AllKeys
                        .ToDictionary(_ => _.ToLower(), _ => query[_] as object)
                        .BuildModel <PuzzleCaptchaModel>();

            var(blockIndexes, imageOrigin, imageBlocks) = await model.GenerateAsync(options);

            await options.SerializeToResponseAsync(context.Response, new
            {
                BlockIndexes = blockIndexes,
                ImageOrigin  = imageOrigin.Encode(ImageFormat.Png),
                ImageBlocks  = imageBlocks.Select(_ => _.Encode(ImageFormat.Png)),
            });

            context.Response.End();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context)
        {
            if (options.RequestConstrainAsync != null)
            {
                if (!await options.RequestConstrainAsync(context))
                {
                    return;
                }
            }

            var query = context.Request.QueryString;
            var model = query.AllKeys
                        .Where(_ => !_.IsNullOrWhiteSpace())
                        .ToDictionary(_ => _.ToLower(), _ => query[_] as object)
                        .BuildModel <ClickCaptchaModel>();

            var(fontPoints, fontImage, boardImage) = await model.GenerateAsync(options);

            await options.SerializeToResponseAsync(context.Response, new
            {
                FontPoints = fontPoints,
                FontImage  = fontImage.Encode(ImageFormat.Png),
                BoardImage = boardImage.Encode(ImageFormat.Png),
            });

            context.Response.End();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context)
        {
            if (options.RequestConstrainAsync != null)
            {
                if (!await options.RequestConstrainAsync(context))
                {
                    return;
                }
            }

            var query = context.Request.QueryString;
            var model = query.AllKeys
                        .ToDictionary(_ => _.ToLower(), _ => query[_] as object)
                        .BuildModel <ArithmeticSpeechCaptchaModel>();

            var(code, audio) = await model.GenerateAsync(options);

            await options.SerializeToResponseAsync(context.Response, new
            {
                Code  = code,
                Audio = Convert.ToBase64String(audio),
            });

            context.Response.End();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context)
        {
            if (options.RequestConstrainAsync != null)
            {
                if (!await options.RequestConstrainAsync(context))
                {
                    return;
                }
            }

            var query = context.Request.QueryString;
            var model = query.AllKeys
                        .ToDictionary(_ => _.ToLower(), _ => query[_] as object)
                        .BuildModel <StringImageCaptchaModel>();

            var(code, image) = await model.GenerateAsync(options);

            await options.SerializeToResponseAsync(context.Response, new
            {
                Code  = code,
                Image = image.Encode(model.Image.GenerateGif ? ImageFormat.Gif : ImageFormat.Png),
            });

            context.Response.End();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context)
        {
            if (options.RequestConstrainAsync != null)
            {
                if (!await options.RequestConstrainAsync(context))
                {
                    return;
                }
            }

            var query = context.Request.QueryString;
            var model = query.AllKeys
                        .ToDictionary(_ => _.ToLower(), _ => query[_] as object)
                        .BuildModel <SliderCaptchaModel>();

            var(blockPoint, originImage, boardImage, blockImage) = await model.GenerateAsync(options);

            await options.SerializeToResponseAsync(context.Response, new
            {
                BlockPoint  = blockPoint,
                OriginImage = originImage.Encode(ImageFormat.Png),
                BoardImage  = boardImage.Encode(ImageFormat.Png),
                BlockImage  = blockImage.Encode(ImageFormat.Png),
            });

            context.Response.End();
        }