Esempio n. 1
0
        public void AssertScriptDivIsCorrectWithCallbacksAndLanguage()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key");
            IHtmlString captcha = ReCaptcha.GetCaptcha(ReCaptchaLanguage.Spanish, "callback", "expiredCallback", "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-expired-callback='expiredCallback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js?hl=es'></script>", captcha.ToHtmlString());
        }
Esempio n. 2
0
        public void AssertScriptDivIsCorrectWithCallbacks()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key");
            IHtmlString captcha1 = ReCaptcha.GetCaptcha(callback: "callback", expiredCallback: "expiredCallback", errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-expired-callback='expiredCallback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha1.ToHtmlString());

            IHtmlString captcha2 = ReCaptcha.GetCaptcha(callback: "callback", errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha2.ToHtmlString());

            IHtmlString captcha3 = ReCaptcha.GetCaptcha(callback: "callback", expiredCallback: "expiredCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-expired-callback='expiredCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha3.ToHtmlString());

            IHtmlString captcha4 = ReCaptcha.GetCaptcha(callback: "callback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha4.ToHtmlString());

            IHtmlString captcha5 = ReCaptcha.GetCaptcha(expiredCallback: "expiredCallback", errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-expired-callback='expiredCallback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha5.ToHtmlString());

            IHtmlString captcha6 = ReCaptcha.GetCaptcha(expiredCallback: "expiredCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-expired-callback='expiredCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha6.ToHtmlString());

            IHtmlString captcha7 = ReCaptcha.GetCaptcha(errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha7.ToHtmlString());
        }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            switch (ProperCaptchaType)
            {
            case CaptchaType.GoogleCaptcha:
                ReCaptcha.Configure(AppSettings.Captcha.ReCAPTCHASiteKey, AppSettings.Captcha.ReCAPTCHASecretKey);
                CaptchaLiteral.Text = ReCaptcha.GetCaptcha(ReCaptchaLanguage.EnglishUs).ToHtmlString();
                IsGoogleCaptchaOk   = 0;
                break;

            case CaptchaType.Titan:
                TitanCaptchaPlaceHolder.Visible = true;
                CaptchaCheckedCustomValidator.ValidationGroup = ValidationGroup;
                CaptchaCheckedCustomValidator.Display         = System.Web.UI.WebControls.ValidatorDisplay.None;
                CaptchaCheckedCustomValidator.ErrorMessage    = U6000.REQCAPTCHA;
                break;

            case CaptchaType.SolveMedia:
                SolveMediaPlaceHolder.Visible = true;
                IsSolveMediaCaptchaOk         = 0;
                break;

            case CaptchaType.Coinhive:
                CoinhivePlaceHolder.Visible = true;
                IsCoinhiveCaptchaOk         = 0;
                break;
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }
Esempio n. 4
0
        public void AssertScriptDivIsCorrectWithLanguageOverrideConfiguration()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key", ReCaptchaLanguage.EnglishUs);
            IHtmlString captcha       = ReCaptcha.GetCaptcha(ReCaptchaLanguage.PortugueseBrazil);
            string      captchaString = captcha.ToHtmlString();

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key'></div><script src='https://www.google.com/recaptcha/api.js?hl=pt-BR'></script>", captchaString);
        }
Esempio n. 5
0
        public void AssertScriptDivIsCorrectWithLanguage()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key", ReCaptchaLanguage.German);
            IHtmlString captcha       = ReCaptcha.GetCaptcha();
            string      captchaString = captcha.ToHtmlString();

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key'></div><script src='https://www.google.com/recaptcha/api.js?hl=de'></script>", captchaString);
        }
Esempio n. 6
0
        public void AssertScriptDivIsCorrectWithDarkThemeOverrride()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key", ReCaptchaLanguage.PortugueseBrazil, ReCaptchaTheme.light);
            IHtmlString captcha       = ReCaptcha.GetCaptcha(theme: ReCaptchaTheme.dark);
            string      captchaString = captcha.ToHtmlString();

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-theme='dark'></div><script src='https://www.google.com/recaptcha/api.js?hl=pt-BR'></script>", captchaString);
        }
Esempio n. 7
0
        public void AssertScriptDivIsCorrect()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key");
            IHtmlString captcha       = ReCaptcha.GetCaptcha();
            string      captchaString = captcha.ToHtmlString();

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-theme='light'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captchaString);
        }
Esempio n. 8
0
        public void AssertScriptDivIsCorrectWithAutoLanguage()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("no");
            ReCaptcha.Configure("my-public-key", "my-secret-key", ReCaptchaLanguage.Auto);

            IHtmlString captcha       = ReCaptcha.GetCaptcha();
            string      captchaString = captcha.ToHtmlString();

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key'></div><script src='https://www.google.com/recaptcha/api.js?hl=no'></script>", captchaString);

            captcha       = ReCaptcha.GetCaptcha(ReCaptchaLanguage.PortugueseBrazil);
            captchaString = captcha.ToHtmlString();
            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key'></div><script src='https://www.google.com/recaptcha/api.js?hl=pt-BR'></script>", captchaString);

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl");
            captcha       = ReCaptcha.GetCaptcha();
            captchaString = captcha.ToHtmlString();
            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key'></div><script src='https://www.google.com/recaptcha/api.js?hl=nl'></script>", captchaString);
        }
Esempio n. 9
0
 public void ExceptionWhenNotConfigured()
 {
     Assert.Throws <ReCaptchaException>(() => ReCaptcha.GetCaptcha());
 }