Skip to content

Commit

Permalink
#2 Compliance with the new invisible captcha
Browse files Browse the repository at this point in the history
Version 1.4.0, added suport for Invisible Captcha.
  • Loading branch information
henriqb committed Apr 20, 2017
1 parent e24c45a commit f7554e8
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 3 deletions.
Binary file modified binary/net45/hbehr.recaptcha.dll
Binary file not shown.
Binary file modified binary/net451/hbehr.recaptcha.dll
Binary file not shown.
Binary file modified binary/net452/hbehr.recaptcha.dll
Binary file not shown.
Binary file modified binary/net46/hbehr.recaptcha.dll
Binary file not shown.
Binary file modified binary/net461/hbehr.recaptcha.dll
Binary file not shown.
Binary file modified binary/net462/hbehr.recaptcha.dll
Binary file not shown.
9 changes: 9 additions & 0 deletions src/hbehr.recaptcha.unittest/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,14 @@ public void AssertScriptDivIsCorrectWithLanguageOverrideConfiguration()
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);
}

[Test]
public void AssertScriptInvisibleDivIsCorrectWithLanguageOverrideConfiguration()
{
ReCaptcha.Configure("my-public-key", "my-secret-key", ReCaptchaLanguage.EnglishUs);
IHtmlString captcha = ReCaptcha.GetInvisibleCaptcha("callback", "SUBMIT",ReCaptchaLanguage.PortugueseBrazil);
string captchaString = captcha.ToHtmlString();
Assert.AreEqual("<button class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback'>SUBMIT</button><script src='https://www.google.com/recaptcha/api.js?hl=pt-BR'></script>", captchaString);
}
}
}
4 changes: 2 additions & 2 deletions src/hbehr.recaptcha/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.1.*")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyVersion("1.4.0.*")]
[assembly: AssemblyFileVersion("1.4.0.0")]
5 changes: 5 additions & 0 deletions src/hbehr.recaptcha/ReCaptcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static IHtmlString GetCaptcha(ReCaptchaLanguage? language = null)
return _reCaptcha.GetCaptcha(language);
}

public static IHtmlString GetInvisibleCaptcha(string callback, string buttonText, ReCaptchaLanguage? language = null)
{
return _reCaptcha.GetInvisibleCaptcha(callback, buttonText, language);
}

public static bool ValidateCaptcha(string response, WebProxy proxy = null)
{
return _reCaptcha.ValidateResponse(new GoogleWebPost(), response, proxy);
Expand Down
9 changes: 8 additions & 1 deletion src/hbehr.recaptcha/ReCaptchaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace hbehr.recaptcha
{
internal class ReCaptchaObject
{
private string _captchaDiv, _secretKey, _language;
private string _captchaDiv, _invisibleCaptchaDiv, _secretKey, _language;
private bool _configured;

internal ReCaptchaObject()
Expand Down Expand Up @@ -84,6 +84,7 @@ private void Initialize(string publicKey, string secretKey, ReCaptchaLanguage? d
_configured = true;
_secretKey = secretKey;
_captchaDiv = string.Format("<div class='g-recaptcha' data-sitekey='{0}'></div><script src='https://www.google.com/recaptcha/api.js{{0}}'></script>", publicKey);
_invisibleCaptchaDiv = string.Format("<button class='g-recaptcha' data-sitekey='{0}' data-callback='{{1}}'>{{2}}</button><script src='https://www.google.com/recaptcha/api.js{{0}}'></script>", publicKey);
}

private string GetHlCode(ReCaptchaLanguage? language)
Expand All @@ -104,6 +105,12 @@ internal IHtmlString GetCaptcha(ReCaptchaLanguage? language)
return new HtmlString(string.Format(_captchaDiv, GetHlCode(language)));
}

internal IHtmlString GetInvisibleCaptcha(string callback, string buttonText, ReCaptchaLanguage? language)
{
CheckIfIamConfigured();
return new HtmlString(string.Format(_invisibleCaptchaDiv, GetHlCode(language), callback, buttonText));
}

internal bool ValidateResponse(IReChaptaWebInterface webInterface, string response)
{
CheckIfIamConfigured();
Expand Down

0 comments on commit f7554e8

Please sign in to comment.