コード例 #1
0
        public static void AddRecaptcha(this IServiceCollection services, Action <RecaptchaOptions> configuration)
        {
            configuration.CheckArgumentNull(nameof(configuration));

            var configureOptions = new RecaptchaOptions();

            configuration(configureOptions);

            AddRecaptcha(services, configureOptions);
        }
コード例 #2
0
        public static void AddRecaptcha(this IServiceCollection services, RecaptchaOptions configureOptions)
        {
            configureOptions.CheckArgumentNull(nameof(configureOptions));

            services.TryAddSingleton(Options.Create(configureOptions));
            services.TryAddSingleton <RecaptchaService>();
            services.TryAddSingleton <IRecaptchaValidationService>((sp) => sp.GetRequiredService <RecaptchaService>());
            services.TryAddSingleton <IRecaptchaConfigurationService>((sp) => sp.GetRequiredService <RecaptchaService>());
            services.TryAddSingleton <ValidateRecaptchaFilter>();
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
コード例 #3
0
        public RecaptchaService(IOptions <RecaptchaOptions> options)
        {
            options.CheckArgumentNull(nameof(options));

            _options = options.Value;

            _options.ResponseValidationEndpoint.CheckMandatoryOption(nameof(_options.ResponseValidationEndpoint));

            _options.JavaScriptUrl.CheckMandatoryOption(nameof(_options.JavaScriptUrl));

            _options.SiteKey.CheckMandatoryOption(nameof(_options.SiteKey));

            _options.SecretKey.CheckMandatoryOption(nameof(_options.SecretKey));

            if (_options.FailAttemptBeforeCaptcha > 0)
            {
                _options.Enabled = false;
            }

            _controlSettings     = _options.ControlSettings ?? new RecaptchaControlSettings();
            _backChannel         = new HttpClient(_options.BackchannelHttpHandler ?? new HttpClientHandler());
            _backChannel.Timeout = _options.BackchannelTimeout;
        }