Пример #1
0
 public LoginModel(SignInManager <IdentityUser> signInManager, ILogger <LoginModel> logger, ICaptchaGenerator captchaGenerator, ICaptchaValidator captchaValidator)
 {
     _signInManager    = signInManager;
     _logger           = logger;
     _captchaGenerator = captchaGenerator;
     _captchaValidator = captchaValidator;
 }
Пример #2
0
 public CaptchaController(IRandomTextGenerator radomTextGenerator, ICaptchaGenerator captchaGenerator)
 {
     this.radomTextGenerator = radomTextGenerator;
     this.captchaGenerator = captchaGenerator;
     string allowChars = ConfigurationManager.AppSettings["CaptchaChars"];
     if (!string.IsNullOrWhiteSpace(allowChars))
         AllowedChars = allowChars;
 }
Пример #3
0
 public AccountController(ISSOClientProvider ssoClientProvider, IObjectProvider<SSOServer> serverProvider, IObjectProvider<SSOClient> clientProvider,
     ICaptchaGenerator captcha, IJsonSerializer jsonSerializer)
 {
     this.ssoClientProvider = ssoClientProvider;
     this.serverProvider = serverProvider;
     this.clientProvider = clientProvider;
     this.captcha = captcha;
     this.jsonSerializer = jsonSerializer;
 }
Пример #4
0
        public static async Task <IActionResult> GetCaptchaFileResultAsync(this ICaptchaGenerator captcha)
        {
            if (!(await captcha.GenerateCaptchaAsync() is FileCaptchaResult result))
            {
                return(null);
            }

            return(new FileContentResult(result.CaptchaByteData, MediaTypeNames.Image.Gif));
        }
Пример #5
0
        public static async Task <IActionResult> GetCaptchaJsonResultAsync(this ICaptchaGenerator captcha)
        {
            if (!(await captcha.GenerateCaptchaAsync() is CaptchaResult result))
            {
                return(null);
            }

            return(new OkObjectResult(result.Properties));
        }
Пример #6
0
 public AccountController(ISSOClientProvider ssoClientProvider, IObjectProvider <SSOServer> serverProvider, IObjectProvider <SSOClient> clientProvider,
                          ICaptchaGenerator captcha, IJsonSerializer jsonSerializer)
 {
     this.ssoClientProvider = ssoClientProvider;
     this.serverProvider    = serverProvider;
     this.clientProvider    = clientProvider;
     this.captcha           = captcha;
     this.jsonSerializer    = jsonSerializer;
 }
Пример #7
0
        public CaptchaController(IRandomTextGenerator radomTextGenerator, ICaptchaGenerator captchaGenerator)
        {
            this.radomTextGenerator = radomTextGenerator;
            this.captchaGenerator   = captchaGenerator;
            string allowChars = ConfigurationManager.AppSettings["CaptchaChars"];

            if (!string.IsNullOrWhiteSpace(allowChars))
            {
                AllowedChars = allowChars;
            }
        }
        public DefaultCaptchaManager(IClock clock,
                                     ICaptchaGenerator captchaGenerator,
                                     ICurrentTenant currentTenant,
                                     ISettingProvider settingProvider,
                                     ISmsCaptchaSender smsCaptchaSender,
                                     IEmailCaptchaSender emailCaptchaSender,
                                     ICaptchaStore captchaStore)
        {
            Clock              = clock;
            CaptchaGenerator   = captchaGenerator;
            CurrentTenant      = currentTenant;
            SettingProvider    = settingProvider;
            SmsCaptchaSender   = smsCaptchaSender;
            EmailCaptchaSender = emailCaptchaSender;
            CaptchaStore       = captchaStore;

            Logger = NullLogger <DefaultCaptchaManager> .Instance;
        }
Пример #9
0
        /// <summary>
        /// Generates the form fields' HTML for spam prevention. Use inside of an ASP.NET MVC form.
        /// </summary>
        /// <param name="htmlHelper">The view's HTML helper.</param>
        /// <param name="fallbackMessage">An optional message to display above the CAPTCHA when it is displayed as a fallback.</param>
        /// <returns>The spam prevention form fields' HTML</returns>
        public static IHtmlString SpamPreventionFields(
            this HtmlHelper htmlHelper,
            string fallbackMessage = null)
        {
            ICaptchaGenerator captchaGenerator = null;

            if (DependencyResolver.Current != null)
            {
                captchaGenerator = DependencyResolver.Current.GetService <ICaptchaGenerator>();
            }
            if (captchaGenerator == null)
            {
                captchaGenerator = new ReCaptchaGenerator();
            }

            var useCaptcha = htmlHelper.ViewData.ModelState.ContainsKey(Const.ModelStateKey);

            if (useCaptcha)
            {
                return(captchaGenerator.Generate(htmlHelper, fallbackMessage));
            }

            //Session hacks
            var    session = htmlHelper.ViewContext.HttpContext.Session;
            var    guidKey = "_" + Const.NoCaptchaChallengeField;
            string guid;

            if (session[guidKey] != null)
            {
                guid = (string)session[guidKey];
            }
            else
            {
                guid = Guid.NewGuid().ToString("N");
            }

            //set guid into session for using again later
            session[guidKey] = guid;
            //--

            return(htmlHelper.Hidden(Const.NoCaptchaChallengeField, guid));
        }
Пример #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);


            services.AddSingleton <IConfigurationSection>(Configuration.GetSection("Captcha"));

            var sp = services.BuildServiceProvider();

            var genTypeName = Configuration.GetValue <string>("Captcha:GeneratorType");

            if (string.IsNullOrEmpty(genTypeName))
            {
                services.AddSingleton <ICaptchaGenerator, EnglishAlphaNumericProvider>();
            }
            else
            {
                var type = Type.GetType(genTypeName, true);
                ICaptchaGenerator generator = (ICaptchaGenerator)ActivatorUtilities.CreateInstance(sp, type);
                services.AddSingleton <ICaptchaGenerator>(generator);
            }

            var repoTypeName = Configuration.GetValue <string>("Captcha:RepositoryType");

            if (string.IsNullOrEmpty(repoTypeName))
            {
                services.AddSingleton <ICaptchaRepository, CaptchaInMemoryRepository>();
            }
            else
            {
                var type = Type.GetType(repoTypeName, true);
                ICaptchaRepository repository = (ICaptchaRepository)ActivatorUtilities.CreateInstance(sp, type);
                services.AddSingleton <ICaptchaRepository>(repository);
            }
        }
Пример #11
0
        /// <summary>
        /// Generates the form fields' HTML for spam prevention. Use inside of an ASP.NET MVC form.
        /// </summary>
        /// <param name="htmlHelper">The view's HTML helper.</param>
        /// <param name="fallbackMessage">An optional message to display above the CAPTCHA when it is displayed as a fallback.</param>
        /// <returns>The spam prevention form fields' HTML</returns>
        public static IHtmlString SpamPreventionFields(
            this HtmlHelper htmlHelper,
            string fallbackMessage = null)
        {
            ICaptchaGenerator captchaGenerator = null;

            if (DependencyResolver.Current != null)
            {
                captchaGenerator = DependencyResolver.Current.GetService <ICaptchaGenerator>();
            }
            if (captchaGenerator == null)
            {
                captchaGenerator = new ReCaptchaGenerator();
            }

            var useCaptcha = htmlHelper.ViewData.ModelState.ContainsKey(Const.ModelStateKey);

            if (useCaptcha)
            {
                return(captchaGenerator.Generate(htmlHelper, fallbackMessage));
            }

            return(htmlHelper.Hidden(Const.NoCaptchaChallengeField, Guid.NewGuid().ToString("N")));
        }
Пример #12
0
 public CaptchaController(ICaptchaGenerator captchaGenerator)
 {
     _captchaGenerator = captchaGenerator;
 }
Пример #13
0
 public CaptchaController(ICaptchaGenerator generator, ICaptchaRepository repository)
 {
     _generator  = generator;
     _repository = repository;
 }