internal ReCaptchaObject()
        {
            // Auto .config configuration
            var reader = new AppSettingsReader();

            try
            {
                string secretKey = reader.GetValue("recaptcha-secret-key", typeof(string)).ToString();
                string publicKey = reader.GetValue("recaptcha-public-key", typeof(string)).ToString();

                Initialize(publicKey, secretKey);
            }
            catch
            {
                // No configuration on .config
            }
            try
            {
                _language = reader.GetValue("recaptcha-language-key", typeof(string)).ToString();
                if ("AUTO".Equals(_language, StringComparison.InvariantCultureIgnoreCase))
                {
                    _defaultLanguage = ReCaptchaLanguage.Auto;
                }
            }
            catch
            {
                // No language on .config
            }

            _defaultTheme = ReCaptchaTheme.light;
            try
            {
                var theme = reader.GetValue("recaptcha-language-theme", typeof(string)).ToString();
                if ("dark".Equals(theme))
                {
                    _defaultTheme = ReCaptchaTheme.dark;
                }
            }
            catch
            {
                // No language on .config
            }
        }
 private void Initialize(string publicKey, string secretKey, ReCaptchaLanguage?defaultLanguage = null, ReCaptchaTheme theme = ReCaptchaTheme.light)
 {
     if (string.IsNullOrWhiteSpace(publicKey))
     {
         throw new ArgumentNullException("publicKey");
     }
     if (string.IsNullOrWhiteSpace(secretKey))
     {
         throw new ArgumentNullException("secretKey");
     }
     _defaultLanguage = defaultLanguage;
     if (defaultLanguage.HasValue)
     {
         _language = defaultLanguage.Value.GetLanguage();
     }
     _defaultTheme        = theme;
     _configured          = true;
     _secretKey           = secretKey;
     _captchaDiv          = string.Format("<div class='g-recaptcha' data-sitekey='{0}'{{1}} data-theme='{{2}}'></div><script src='https://www.google.com/recaptcha/api.js{{0}}'></script>", publicKey);
     _invisibleCaptchaDiv = string.Format("<button class='{{1}}' data-sitekey='{0}' data-callback='{{2}}'>{{3}}</button><script src='https://www.google.com/recaptcha/api.js{{0}}'></script>", publicKey);
 }
Exemplo n.º 3
0
 public static void Configure(string publicKey, string secretKey, ReCaptchaLanguage?defaultLanguage = null, ReCaptchaTheme theme = ReCaptchaTheme.light)
 {
     _reCaptcha = new ReCaptchaObject(publicKey, secretKey, defaultLanguage, theme);
 }
 public static MvcHtmlString ReCaptcha(this HtmlHelper helper, string siteKey, ReCaptchaTheme theme, int tabIndex)
 {
     return(MvcHtmlString.Create(String.Format("<div class=\"g-recaptcha\" data-sitekey=\"{0}\" data-theme=\"{1}\" data-tabindex=\"{2}\"></div>", siteKey, theme.ToString().ToLower(), tabIndex)));
 }
 /// <summary>
 /// This one uses the configuration key in the web.config
 /// </summary>
 public static MvcHtmlString ReCaptcha(this HtmlHelper helper, ReCaptchaTheme theme, int tabIndex)
 {
     return(ReCaptcha(helper, ConfigurationManager.AppSettings[ConfigurationKeys.SiteKey], theme, tabIndex));
 }
 internal ReCaptchaObject(string publicKey, string secretKey, ReCaptchaLanguage?defaultLanguage = null, ReCaptchaTheme theme = ReCaptchaTheme.light)
 {
     Initialize(publicKey, secretKey, defaultLanguage, theme);
 }