Esempio n. 1
0
        /// <summary>
        /// Create partial captcha
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static RefreshModel GeneratePartialCaptcha(RequestContext requestContext, int length)
        {
            var encryptorModel = GetEncryptorModel();
            var captchaText    = RandomText.Generate(length);
            var encryptText    = GetEncryption().Encrypt(captchaText, encryptorModel.Password, encryptorModel.Salt);
            var urlHelper      = new UrlHelper(requestContext);
            var url            = urlHelper.Action("Create", "CaptchaImage", new { encryptText });

            return(new RefreshModel()
            {
                Code = encryptText, Image = url
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Create full captcha
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="text"></param>
        /// <param name="inputText"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static MvcHtmlString GenerateFullCaptcha(HtmlHelper htmlHelper, string text, string inputText, int length)
        {
            var encryptorModel = GetEncryptorModel();
            var captchaText    = RandomText.Generate(length);
            var encryptText    = GetEncryption().Encrypt(captchaText, encryptorModel.Password, encryptorModel.Salt);
            var urlHelper      = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            var url            = urlHelper.Action("Create", "CaptchaImage", new { encryptText });
            var ajax           = new AjaxHelper(htmlHelper.ViewContext, htmlHelper.ViewDataContainer);
            var refresh        = ajax.ActionLink(text, "NewCaptcha", "CaptchaImage", new { l = length },
                                                 new AjaxOptions {
                UpdateTargetId = "CaptchaDeText", OnSuccess = "Success"
            });
            string tgs = "<div style=\"float: left; margin-top: 5px;\">" + refresh.ToHtmlString() + " <br/>" + inputText + "<br/>" +
                         htmlHelper.TextBox("CaptchaInputText", "", new { data_val_required = "*", data_val = "true", data_val_length_min = "5", data_val_length_max = "5", data_val_length = "*" }) +
                         htmlHelper.ValidationMessage("CaptchaInputText") + "</div>";

            return(MvcHtmlString.Create(tgs + string.Format(CaptchaFormat, url, htmlHelper.Hidden("CaptchaDeText", encryptText))));
        }