コード例 #1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (OnValidationFailedAction == ValidationFailedAction.Unspecified)
            {
                OnValidationFailedAction = _options.ValidationFailedAction;
            }

            ValidationResponse validationResponse;

            if (!TryGetRecaptchaToken(context.HttpContext.Request, out string?token))
            {
                _logger.RecaptchaResponseTokenMissing();

                validationResponse = new ValidationResponse()
                {
                    Success       = false,
                    ErrorMessages = new List <string>()
                    {
                        "missing-input-response"
                    }
                };
            }
            else
            {
                validationResponse = await _recaptchaService.ValidateRecaptchaResponse(token, GetRemoteIp(context)).ConfigureAwait(true);
            }

            TryAddResponseToActionAguments(context, validationResponse);

            if (!ShouldShortCircuit(context, validationResponse))
            {
                await next.Invoke().ConfigureAwait(true);
            }
        }