/// <summary>
        /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param>
        /// <param name="publicKey">Sets the public key of recaptcha.</param>
        /// <param name="theme">Sets the theme of recaptcha.</param>
        /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param>
        /// <param name="tabIndex">Sets the tab index of recaptcha.</param>
        /// <param name="dataType">Sets the data type of recaptcha.</param>
        /// <param name="dataSize">Sets the size of recaptcha.</param>
        /// <param name="useSsl">Sets the value to the UseSsl property.</param>
        /// <param name="apiVersion">Determines the version of the reCAPTCHA API.</param>
        /// <returns>Returns an instance of the IHtmlString type.</returns>
        public static IHtmlString Recaptcha(
            this HtmlHelper htmlHelper,
            string publicKey = "{recaptchaPublicKey}",
            RecaptchaTheme theme = RecaptchaTheme.Red,
            string language = null,
            int tabIndex = 0,
            RecaptchaDataType? dataType = null,
            RecaptchaDataSize? dataSize = null,
            SslBehavior useSsl = SslBehavior.SameAsRequestUrl,
            string apiVersion = "{recaptchaApiVersion}")
        {
            IRecaptchaHtmlHelper rHtmlHelper = null;

            string version = RecaptchaKeyHelper.ParseKey(apiVersion);

            if (version != "2")
            {
                rHtmlHelper = new RecaptchaHtmlHelper(publicKey, theme, language, tabIndex, useSsl);
            }
            else
            {
                rHtmlHelper = new Recaptcha2HtmlHelper(publicKey, theme, language, tabIndex, dataType, dataSize, useSsl);
            }

            var writer = new HtmlTextWriter(new StringWriter());
            writer.Write(rHtmlHelper.ToString());

            return htmlHelper.Raw(writer.InnerWriter.ToString());
        }
Exemple #2
0
        /// <summary>
        /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param>
        /// <param name="publicKey">Sets the public key of recaptcha.</param>
        /// <param name="theme">Sets the theme of recaptcha.</param>
        /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param>
        /// <param name="tabIndex">Sets the tab index of recaptcha.</param>
        /// <param name="dataType">Sets the data type of recaptcha.</param>
        /// <param name="dataSize">Sets the size of recaptcha.</param>
        /// <param name="useSsl">Sets the value to the UseSsl property.</param>
        /// <param name="apiVersion">Determines the version of the reCAPTCHA API.</param>
        /// <returns>Returns an instance of the IHtmlString type.</returns>
        public static IHtmlString Recaptcha(
            this HtmlHelper htmlHelper,
            string publicKey           = "{recaptchaPublicKey}",
            RecaptchaTheme theme       = RecaptchaTheme.Red,
            string language            = null,
            int tabIndex               = 0,
            RecaptchaDataType?dataType = null,
            RecaptchaDataSize?dataSize = null,
            SslBehavior useSsl         = SslBehavior.SameAsRequestUrl,
            string apiVersion          = "{recaptchaApiVersion}")
        {
            IRecaptchaHtmlHelper rHtmlHelper = null;

            string version = RecaptchaKeyHelper.ParseKey(apiVersion);

            if (version != "2")
            {
                rHtmlHelper = new RecaptchaHtmlHelper(publicKey, theme, language, tabIndex, useSsl);
            }
            else
            {
                rHtmlHelper = new Recaptcha2HtmlHelper(publicKey, theme, language, tabIndex, dataType, dataSize, useSsl);
            }

            var writer = new HtmlTextWriter(new StringWriter());

            writer.Write(rHtmlHelper.ToString());

            return(htmlHelper.Raw(writer.InnerWriter.ToString()));
        }
        /// <summary>
        /// Creates an instance of the <see cref="RecaptchaHtmlHelper"/> class.
        /// </summary>
        /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
        /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
        /// <param name="language">Sets the language of the recaptcha HTML.</param>
        /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>    
        /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
        public RecaptchaHtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, SslBehavior useSsl)
        {
            this.PublicKey = RecaptchaKeyHelper.ParseKey(publicKey);

            if (String.IsNullOrEmpty(this.PublicKey))
            {
                throw new InvalidOperationException("Public key cannot be null or empty.");
            }

            this.Theme = theme;
            this.Language = language;
            this.TabIndex = tabIndex;

            UseSsl = useSsl;
        }
        /// <summary>
        /// Creates an instance of the <see cref="RecaptchaHtmlHelper"/> class.
        /// </summary>
        /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
        /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
        /// <param name="language">Sets the language of the recaptcha HTML.</param>
        /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>
        /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
        public RecaptchaHtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, SslBehavior useSsl)
        {
            this.PublicKey = RecaptchaKeyHelper.ParseKey(publicKey);

            if (String.IsNullOrEmpty(this.PublicKey))
            {
                throw new InvalidOperationException("Public key cannot be null or empty.");
            }

            this.Theme    = theme;
            this.Language = language;
            this.TabIndex = tabIndex;

            UseSsl = useSsl;
        }
        /// <summary>
        /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param>
        /// <param name="publicKey">Sets the public key of recaptcha.</param>
        /// <param name="theme">Sets the theme of recaptcha.</param>
        /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param>
        /// <param name="tabIndex">Sets the tab index of recaptcha.</param>
        /// <param name="useSsl">Sets the value to the UseSsl property.</param>
        /// <returns>Returns an instance of the IHtmlString type.</returns>
        public static IHtmlString Recaptcha(
            this HtmlHelper htmlHelper,
            string publicKey = "{recaptchaPublicKey}",
            RecaptchaTheme theme = RecaptchaTheme.Red,
            string language = null,
            int tabIndex = 0,
            SslBehavior useSsl = SslBehavior.SameAsRequestUrl)
        {
            RecaptchaHtmlHelper rHtmlHelper = new RecaptchaHtmlHelper(publicKey, theme, language, tabIndex, useSsl);

            HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
            writer.Write(rHtmlHelper.ToString());

            return htmlHelper.Raw(writer.InnerWriter.ToString());
        }
        /// <summary>
        /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param>
        /// <param name="publicKey">Sets the public key of recaptcha.</param>
        /// <param name="theme">Sets the theme of recaptcha.</param>
        /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param>
        /// <param name="tabIndex">Sets the tab index of recaptcha.</param>
        /// <param name="useSsl">Sets the value to the UseSsl property.</param>
        /// <returns>Returns an instance of the IHtmlString type.</returns>
        public static IHtmlString Recaptcha(
            this HtmlHelper htmlHelper,
            string publicKey     = "{recaptchaPublicKey}",
            RecaptchaTheme theme = RecaptchaTheme.Red,
            string language      = null,
            int tabIndex         = 0,
            SslBehavior useSsl   = SslBehavior.SameAsRequestUrl)
        {
            RecaptchaHtmlHelper rHtmlHelper = new RecaptchaHtmlHelper(publicKey, theme, language, tabIndex, useSsl);

            HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());

            writer.Write(rHtmlHelper.ToString());

            return(htmlHelper.Raw(writer.InnerWriter.ToString()));
        }
 /// <summary>
 /// Creates an instance of the <see cref="Recaptcha2HtmlHelper"/> class.
 /// </summary>
 /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
 /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
 /// <param name="language">Sets the language of the recaptcha HTML.</param>
 /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>
 /// <param name="dataType">Sets the type of the recaptcha HTML.</param>
 /// <param name="dataSize">Sets the size for the recpatcha HTML.</param>
 /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
 /// <param name="dataCallback">Sets the data-callback property of the recaptcha HTML.</param>
 /// <param name="dataExpiredCallback">Sets the data-expired-callback property of the recaptcha HTML.</param>
 public Recaptcha2HtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, RecaptchaDataType?dataType, RecaptchaDataSize?dataSize, SslBehavior useSsl, string dataCallback, string dataExpiredCallback)
     : base(publicKey, theme, language, tabIndex, useSsl, dataCallback, dataExpiredCallback)
 {
     DataType            = dataType;
     DataSize            = dataSize;
     DataCallback        = dataCallback;
     DataExpiredCallback = dataExpiredCallback;
 }
 /// <summary>
 /// Creates an instance of the <see cref="Recaptcha2HtmlHelper"/> class.
 /// </summary>
 /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
 /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
 /// <param name="language">Sets the language of the recaptcha HTML.</param>
 /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>
 /// <param name="dataType">Sets the type of the recaptcha HTML.</param>
 /// <param name="dataSize">Sets the size for the recpatcha HTML.</param>
 /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
 public Recaptcha2HtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, RecaptchaDataType?dataType, RecaptchaDataSize?dataSize, SslBehavior useSsl)
     : base(publicKey, theme, language, tabIndex, useSsl)
 {
     DataType = dataType;
     DataSize = dataSize;
 }
 /// <summary>
 /// Creates an instance of the <see cref="Recaptcha2HtmlHelper"/> class.
 /// </summary>
 /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
 /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
 /// <param name="language">Sets the language of the recaptcha HTML.</param>
 /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>
 /// <param name="dataType">Sets the type of the recaptcha HTML.</param>
 /// <param name="dataSize">Sets the size for the recpatcha HTML.</param>
 /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
 /// <param name="withCallback">Determines if we need a callback for our reCaptcha</param>
 public Recaptcha2HtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, RecaptchaDataType?dataType, RecaptchaDataSize?dataSize, SslBehavior useSsl, bool withCallback, string callBack)
     : base(publicKey, theme, language, tabIndex, useSsl, withCallback)
 {
     DataType     = dataType;
     DataSize     = dataSize;
     CallbackName = callBack;
 }
Exemple #10
0
 /// <summary>
 /// Creates an instance of the <see cref="RecaptchaHtmlHelper"/> class.
 /// </summary>
 /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
 /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
 /// <param name="language">Sets the language of the recaptcha HTML.</param>
 /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>
 /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
 public RecaptchaHtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, SslBehavior useSsl)
     : base(publicKey, theme, language, tabIndex, useSsl)
 {
 }
 /// <summary>
 /// Creates an instance of the <see cref="Recaptcha2HtmlHelper"/> class.
 /// </summary>
 /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
 /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
 /// <param name="language">Sets the language of the recaptcha HTML.</param>
 /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>    
 /// <param name="dataType">Sets the type of the recaptcha HTML.</param>
 /// <param name="dataSize">Sets the size for the recpatcha HTML.</param>
 /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
 public Recaptcha2HtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, RecaptchaDataType? dataType, RecaptchaDataSize? dataSize, SslBehavior useSsl)
     : base(publicKey, theme, language, tabIndex, useSsl)
 {
     DataType = dataType;
     DataSize = dataSize;
 }
 /// <summary>
 /// Creates an instance of the <see cref="RecaptchaHtmlHelper"/> class.
 /// </summary>
 /// <param name="publicKey">Sets the public key of the recaptcha HTML.</param>
 /// <param name="theme">Sets the theme of the recaptcha HTML.</param>
 /// <param name="language">Sets the language of the recaptcha HTML.</param>
 /// <param name="tabIndex">Sets the tab index of the recaptcha HTML.</param>    
 /// <param name="useSsl">Determines whether to use SSL in reCAPTCHA API URLs.</param>
 public RecaptchaHtmlHelper(string publicKey, RecaptchaTheme theme, string language, int tabIndex, SslBehavior useSsl)
     : base(publicKey, theme, language, tabIndex, useSsl)
 { }