/// <summary>
        /// Process the taghelper and generate the output.
        /// </summary>
        public void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.CheckArgumentNull(nameof(context));
            output.CheckArgumentNull(nameof(output));

            setUrlHelper();

            output.TagName = "div";
            output.Attributes.Add("class", "dntCaptcha");
            var captchaDivId = $"dntCaptcha{context.UniqueId}{_randomNumberProvider.Next(Min, Max)}";

            output.Attributes.Add("id", captchaDivId);
            output.TagMode = TagMode.StartTagAndEndTag;

            var number        = _randomNumberProvider.Next(Min, Max);
            var randomText    = _humanReadableIntegerProvider.NumberToText(number, Language);
            var encryptedText = _captchaProtectionProvider.Encrypt(randomText);

            var captchaImage = getCaptchaImageTagBuilder(encryptedText);

            output.Content.AppendHtml(captchaImage);

            var cookieToken   = $".{captchaDivId}";
            var refreshButton = getRefreshButtonTagBuilder(captchaDivId, cookieToken);

            output.Content.AppendHtml(refreshButton);

            var hiddenInput = getHiddenInputTagBuilder(encryptedText);

            output.Content.AppendHtml(hiddenInput);

            var textInput = getTextInputTagBuilder();

            output.Content.AppendHtml($"{string.Format(TextBoxTemplate, textInput.GetString())}");

            var validationMessage = getValidationMessageTagBuilder();

            output.Content.AppendHtml(validationMessage);

            var hiddenInputToken = getHiddenInputTokenTagBuilder(_captchaProtectionProvider.Encrypt(cookieToken));

            output.Content.AppendHtml(hiddenInputToken);

            var dataAjaxBeginScript = getOnRefreshButtonDataAjaxBegin();

            output.Content.AppendHtml(dataAjaxBeginScript);

            _captchaStorageProvider.Add(ViewContext.HttpContext, cookieToken, randomText);
        }
Example #2
0
        /// <summary>
        /// Process the taghelper and generate the output.
        /// </summary>
        public void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.CheckArgumentNull(nameof(context));
            output.CheckArgumentNull(nameof(output));

            output.TagName = "div";
            output.Attributes.Add("class", "captcha");
            var captchaDivId = $"captcha{context.UniqueId}{_randomNumberProvider.Next(Min, Max)}";

            output.Attributes.Add("id", captchaDivId);
            output.TagMode = TagMode.StartTagAndEndTag;

            var number     = _randomNumberProvider.Next(Min, Max);
            var randomText = "";

            randomText = OutputType == OutputType.InDigits ? DNTPersianUtils.Core.PersianNumbersUtils.ToPersianNumbers(number) : _humanReadableIntegerProvider.NumberToText(number, Language);

            var encryptedText = _captchaProtectionProvider.Encrypt(randomText);

            var captchaImage = GetCaptchaImageTagBuilder(encryptedText);

            output.Content.AppendHtml(captchaImage);

            var cookieToken   = $".{captchaDivId}";
            var refreshButton = GetRefreshButtonTagBuilder(captchaDivId, cookieToken);

            output.Content.AppendHtml(refreshButton);

            var hiddenInput = GetHiddenInputTagBuilder(encryptedText);

            output.Content.AppendHtml(hiddenInput);
            if (!ImageOnly)
            {
                var textInput = GetTextInputTagBuilder();
                output.Content.AppendHtml($"{string.Format(TextBoxTemplate, textInput.GetString())}");
            }

            var validationMessage = GetValidationMessageTagBuilder();

            output.Content.AppendHtml(validationMessage);

            var hiddenInputToken = GetHiddenInputTokenTagBuilder(_captchaProtectionProvider.Encrypt(cookieToken));

            output.Content.AppendHtml(hiddenInputToken);

            _captchaStorageProvider.Add(ViewContext.HttpContext, cookieToken, randomText);
        }