Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captcha and Recaptcha, closes #21 #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -11,6 +11,10 @@
*.sln.docstates
*.local.sln
*.sln.GhostDoc.xml
DotNetNuke.Modules.UserDefinedTable.xml
web.config
web.Debug.config
web.Release.config

## Ignore VS2015/Roslyn artifacts
*.sln.ide/
Expand Down
6 changes: 6 additions & 0 deletions App_LocalResources/form.ascx.resx
Expand Up @@ -159,4 +159,10 @@
<data name="MonthNames.Text" xml:space="preserve">
<value>'January','Februrary','March','April','May','June','July','August','September','October','November','December'</value>
</data>
<data name="ReCaptcha.Text" xml:space="preserve">
<value>ReCaptcha</value>
</data>
<data name="ReCaptchaError.Text" xml:space="preserve">
<value>An unexpected error has occured, please try again.</value>
</data>
</root>
32 changes: 28 additions & 4 deletions App_LocalResources/settings.ascx.resx
Expand Up @@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ModuleHelp.Text" xml:space="preserve">
<value>&lt;h1&gt;Specific Settings for Form and List Module&lt;/h1&gt;
Expand Down Expand Up @@ -145,8 +145,8 @@
<data name="EditOwnData.Text" xml:space="preserve">
<value>Users are only allowed to manipulate their own items.</value>
</data>
<data name="ForceCaptcha.Text" xml:space="preserve">
<value>Force CAPTCHA control during edit for Anonymous users.</value>
<data name="lblForceCaptcha.Text" xml:space="preserve">
<value>Force CAPTCHA for Anonymous users.</value>
</data>
<data name="InputFiltering.Text" xml:space="preserve">
<value>Filter entry for markup code or script input. Note: filtering is always enabled for Anonymous users.</value>
Expand All @@ -166,4 +166,28 @@
<data name="DisplaySystemColumns.Text" xml:space="preserve">
<value>Hide System Fields even if "Display All Column" permission is set.</value>
</data>
<data name="lblForceCaptcha.Help" xml:space="preserve">
<value>Select the captcha type to use for anonymous users.</value>
</data>
<data name="DnnCaptcha.Text" xml:space="preserve">
<value>DnnCaptcha</value>
</data>
<data name="No.Text" xml:space="preserve">
<value>No</value>
</data>
<data name="ReCaptcha.Text" xml:space="preserve">
<value>ReCaptcha</value>
</data>
<data name="lblSecretKey.Help" xml:space="preserve">
<value>Obtain your secret key at &lt;a href="https://www.google.com/recaptcha" target="_blank"&gt;https://www.google.com/recaptcha&lt;/a&gt;</value>
</data>
<data name="lblSecretKey.Text" xml:space="preserve">
<value>ReCaptcha Secret Key</value>
</data>
<data name="lblSiteKey.Help" xml:space="preserve">
<value>Obtain your site key at &lt;a href="https://www.google.com/recaptcha" target="_blank"&gt;https://www.google.com/recaptcha&lt;/a&gt;</value>
</data>
<data name="lblSiteKey.Text" xml:space="preserve">
<value>ReCaptcha Site Key</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Components/GlobalConstants.cs
Expand Up @@ -130,6 +130,9 @@ public class SettingName
public const string URLSearch = "UDT_URLSearch";
// public const string UseButtons = "UDT_UseButtons";
public const string ForceCaptchaForAnonymous = "UDT_ForceCaptchaForAnonymous";
public const string PreferReCaptcha = "UDT_PreferReCaptcha";
public const string ReCaptchaSiteKey = "UDT_ReCaptchaSiteKey";
public const string ReCaptchaSecretKey = "UDT_ReCaptchaPrivateKey";
public const string ForceInputFiltering = "UDT_ForceFiltering";
public const string EditOnlyOwnItems = "UDT_EditOnlyOwnItems";
public const string ExcludeFromSearch = "UDT_ExcludeFromSearch";
Expand Down
25 changes: 25 additions & 0 deletions Components/ReCaptcha.cs
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;

namespace DotNetNuke.Modules.UserDefinedTable.Components
{
public class ReCaptcha
{
public static bool Validate(string encodedResponse, string privateKey)
{
var client = new System.Net.WebClient();
var googleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", privateKey, encodedResponse));
var captchaResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<ReCaptcha>(googleReply);
return captchaResponse.Success;
}

[JsonProperty("success")]
public bool Success { get; set; }

[JsonProperty("error-codes")]
public List<string> ErrorCodes { get; set; }
}
}
12 changes: 12 additions & 0 deletions Components/ReCaptchaReply.cs
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotNetNuke.Modules.UserDefinedTable.Components
{
public class ReCaptchaReply
{
public bool Success { get; set; }
}
}
15 changes: 15 additions & 0 deletions Components/Settings.cs
Expand Up @@ -37,6 +37,21 @@ public bool ForceCaptchaForAnonymous
get { return _settings[SettingName.ForceCaptchaForAnonymous].AsBoolean(); }
}

public bool PreferReCaptcha
{
get { return _settings[SettingName.PreferReCaptcha].AsBoolean(); }
}

public string ReCaptchaSiteKey
{
get { return _settings[SettingName.ReCaptchaSiteKey].AsString(); }
}

public string ReCaptchaSecretKey
{
get { return _settings[SettingName.ReCaptchaSecretKey].AsString(); }
}

public string ListOrForm
{
get { return _settings[SettingName.ListOrForm].AsString("List"); }
Expand Down
114 changes: 84 additions & 30 deletions DotNetNuke.Modules.UserDefinedTable.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.