Ejemplo n.º 1
0
        void IValidator.Validate()
        {
            if (string.IsNullOrEmpty(SecretKey))
            {
                throw new InvalidOperationException("Secret Key is required");
            }

            _isValid = Recaptcha2Validator.Validate(SecretKey);
        }
Ejemplo n.º 2
0
        void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
        {
            var provider  = ResolveSecretKeyProvider();
            var secretKey = provider.GetSecretKey();
            var isValid   = Recaptcha2Validator.Validate(secretKey);

            if (!isValid)
            {
                var error = !string.IsNullOrEmpty(ErrorMessage) ? ErrorMessage : Constants.DefaultErrorMessage;
                filterContext.Controller.ViewData.ModelState.AddModelError("NRecaptcha2ValidationError", error);
            }
        }