Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a new captcha with the specified arguments.
        /// </summary>
        /// <param name="htmlHelper">
        ///     The specified <see cref="HtmlHelper" />.
        /// </param>
        /// <param name="length">The specified length of characters.</param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     An instance of <see cref="ICaptcha" />.
        /// </returns>
        public static ICaptcha Captcha(this HtmlHelper htmlHelper, int length, params ParameterModel[] parameters)
        {
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);

            list.Add(new ParameterModel(DefaultCaptchaManager.LengthAttribute, length));
            return(CaptchaUtils.GenerateCaptcha(htmlHelper, list));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Determines whether the captcha is valid, and write error message if need.
        /// </summary>
        /// <param name="controllerBase">
        ///     The specified <see cref="ControllerBase" />.
        /// </param>
        /// <param name="errorText">The specified error message.</param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     <c>True</c> if the captcha is valid; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsCaptchaValid(this ControllerBase controllerBase, string errorText,
                                          params ParameterModel[] parameters)
        {
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);

            list.Add(new ParameterModel(DefaultCaptchaManager.ErrorAttribute, errorText));
            return(CaptchaUtils.ValidateCaptcha(controllerBase, list));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Creates a new math captcha values with the specified arguments.
        /// </summary>
        /// <param name="controller">
        ///     The specified <see cref="ControllerBase" />.
        /// </param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     An instance of <see cref="IUpdateInfoModel" />.
        /// </returns>
        public static IUpdateInfoModel GenerateMathCaptchaValue(this ControllerBase controller, params ParameterModel[] parameters)
        {
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);

            list.Add(new ParameterModel(DefaultCaptchaManager.MathCaptchaAttribute, true));
            var container = new CombinedParameterContainer(new ParameterModelContainer(list), new RequestParameterContainer(controller.ControllerContext.HttpContext.Request));

            return(controller.GetCaptchaManager().GenerateNew(controller, container));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Creates a new math captcha with the specified arguments.
        /// </summary>
        /// <param name="htmlHelper">
        ///     The specified <see cref="HtmlHelper" />.
        /// </param>
        /// <param name="refreshText">The specified refresh button text.</param>
        /// <param name="inputText">The specified input text.</param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     An instance of <see cref="ICaptcha" />.
        /// </returns>
        public static ICaptcha MathCaptcha(this HtmlHelper htmlHelper, string refreshText, string inputText,
                                           params ParameterModel[] parameters)
        {
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);

            list.Add(new ParameterModel(DefaultCaptchaManager.InputTextAttribute, inputText));
            list.Add(new ParameterModel(DefaultCaptchaManager.RefreshTextAttribute, refreshText));
            list.Add(new ParameterModel(DefaultCaptchaManager.MathCaptchaAttribute, true));
            return(CaptchaUtils.GenerateCaptcha(htmlHelper, list));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Makes the captcha "intelligent".
        /// </summary>
        /// <param name="captcha">
        ///     The specified <see cref="ICaptcha" />.
        /// </param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     An instance of <see cref="ICaptcha" />.
        /// </returns>
        public static ICaptcha AsIntelligent(this ICaptcha captcha, params ParameterModel[] parameters)
        {
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);
            var container      = new CombinedParameterContainer(new ParameterModelContainer(list), captcha.BuildInfo.ParameterContainer);
            var captchaManager = CaptchaUtils.CaptchaManagerFactory(container);

            if (captchaManager.IntelligencePolicy == null)
            {
                throw new NullReferenceException("The IntelligencePolicy property is null.");
            }
            return(captchaManager.IntelligencePolicy.MakeIntelligent(captchaManager, captcha, container));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Creates a new captcha with the specified arguments.
        /// </summary>
        /// <param name="htmlHelper">
        ///     The specified <see cref="HtmlHelper" />.
        /// </param>
        /// <param name="refreshText">The specified refresh button text.</param>
        /// <param name="inputText">The specified input text.</param>
        /// <param name="length">The specified length of characters.</param>
        /// <param name="requiredMessageText">The specified required message text.</param>
        /// <param name="addValidationSpan">
        ///     If <c>true</c> add a span for validation; otherwise <c>false</c>.
        /// </param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     An instance of <see cref="ICaptcha" />.
        /// </returns>
        public static ICaptcha Captcha(this HtmlHelper htmlHelper, string refreshText, string inputText,
                                       int length, string requiredMessageText, bool addValidationSpan = false,
                                       params ParameterModel[] parameters)
        {
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);

            list.Add(new ParameterModel(DefaultCaptchaManager.InputTextAttribute, inputText));
            list.Add(new ParameterModel(DefaultCaptchaManager.RefreshTextAttribute, refreshText));
            list.Add(new ParameterModel(DefaultCaptchaManager.LengthAttribute, length));
            list.Add(new ParameterModel(DefaultCaptchaManager.IsRequiredAttribute, true));
            list.Add(new ParameterModel(DefaultCaptchaManager.RequiredMessageAttribute, requiredMessageText));
            list.Add(new ParameterModel(DefaultCaptchaManager.IsNeedValidationSpanAttribute, addValidationSpan));
            return(CaptchaUtils.GenerateCaptcha(htmlHelper, list));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Creates a new math captcha with the specified partial view.
        /// </summary>
        /// <param name="htmlHelper">
        ///     The specified <see cref="HtmlHelper" />.
        /// </param>
        /// <param name="partialViewName">The name of the partial view to render.</param>
        /// <param name="viewData">The view data dictionary for the partial view.</param>
        /// <param name="parameters">The specified parameters, if any.</param>
        /// <returns>
        ///     An instance of <see cref="ICaptcha" />.
        /// </returns>
        public static ICaptcha MathCaptcha(this HtmlHelper htmlHelper, [AspMvcPartialView] string partialViewName,
                                           ViewDataDictionary viewData = null, params ParameterModel[] parameters)
        {
            Validate.ArgumentNotNullOrEmpty(partialViewName, "partialViewName");
            List <ParameterModel> list = CaptchaUtils.GetParameters(parameters);

            list.Add(new ParameterModel(DefaultCaptchaManager.MathCaptchaAttribute, true));
            list.Add(new ParameterModel(DefaultCaptchaManager.PartialViewNameAttribute, partialViewName));
            if (viewData != null)
            {
                list.Add(new ParameterModel(DefaultCaptchaManager.PartialViewDataAttribute, viewData));
            }
            return(CaptchaUtils.GenerateCaptcha(htmlHelper, list));
        }