コード例 #1
0
        public IEnumerable <ValidationError> Validate(IDictionary <string, KeyValuePair <Type, object> > pluginProperties)
        {
            //todo: (nheskew) skip key validation until we can get at the blog URI
            //note: (nheskew) error messages weren't showing up for me. don't know if it's my box but errors returned were just ignored on save
            return(new List <ValidationError>());

            SpamControlPlugin spamControlPlugin = new SpamControlPlugin
            {
                ApiEndpoint = pluginProperties.ContainsKey("ApiEndpoint") ? pluginProperties["ApiEndpoint"].Value as string : null,
                ApiKey      = pluginProperties.ContainsKey("ApiKey") ? pluginProperties["ApiKey"].Value as string : null
            };

            ApiKeyValidationResponse apiKeyValidationResponse = runApiKeyValidation(spamControlPlugin.GetApiKeyVerificationUri("verify-key"), new ApiKeyCandidate {
                blog = null, key = spamControlPlugin.ApiKey
            });

            List <ValidationError> errors = new List <ValidationError>();

            if (apiKeyValidationResponse == null)
            {
                //todo: (nheskew) add more debug info to the error message
                errors.Add(new ValidationError("ApiKey", spamControlPlugin, "Plugins.Errors.ApiKeyValidator.UnableToValidate", "en", "The API key validation completely failed."));
                return(errors);
            }

            if (!apiKeyValidationResponse.IsValid)
            {
                errors.Add(new ValidationError("ApiKey", spamControlPlugin, "Plugins.Errors.ApiKeyValidator.InvalidKey", "en", "API key valididation failed. Message: {1}", apiKeyValidationResponse.Status, apiKeyValidationResponse.Message));
            }

            return(errors);
        }
コード例 #2
0
        public IEnumerable <ValidationError> Validate(IDictionary <string, KeyValuePair <Type, object> > pluginProperties, ValidationState validationState, OxiteContext context)
        {
            List <ValidationError> errors = new List <ValidationError>();

            if (validationState.Errors.Count > 0)
            {
                return(errors);
            }

            SpamControlPlugin spamControlPlugin = new SpamControlPlugin
            {
                ApiEndpoint = pluginProperties.ContainsKey("ApiEndpoint") ? pluginProperties["ApiEndpoint"].Value as string : null,
                ApiKey      = pluginProperties.ContainsKey("ApiKey") ? pluginProperties["ApiKey"].Value as string : null
            };

            ApiKeyValidationResponse apiKeyValidationResponse = runApiKeyValidation(
                spamControlPlugin.GetApiKeyVerificationUri("verify-key"),
                new ApiKeyCandidate
            {
                blog = new Uri(context.Site.Host, context.HttpContext.Request.ApplicationPath),
                key  = spamControlPlugin.ApiKey
            },
                context
                );

            if (apiKeyValidationResponse == null)
            {
                //todo: (nheskew) add more debug info to the error message
                errors.Add(new ValidationError("ApiKey", spamControlPlugin, "Plugins.Errors.ApiKeyValidator.UnableToValidate", "en", "The API key validation completely failed."));
                return(errors);
            }

            if (!apiKeyValidationResponse.IsValid)
            {
                errors.Add(new ValidationError("ApiKey", spamControlPlugin, "Plugins.Errors.ApiKeyValidator.InvalidKey", "en", "API key valididation failed.{0}", !string.IsNullOrEmpty(apiKeyValidationResponse.Message) ? " Message: " + apiKeyValidationResponse.Message : ""));
            }

            return(errors);
        }