Skip to content

Commit

Permalink
ventrian#19 Replace DNN Captcha optionally with reCaptcha or Honeypot
Browse files Browse the repository at this point in the history
  • Loading branch information
skamphuis committed Nov 26, 2018
1 parent 5deaafa commit ab460a0
Show file tree
Hide file tree
Showing 20 changed files with 471 additions and 61 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Installs/NewsArticles.00.09.11/
Installs/NewsArticles.00.10.00/
InstallPackager/
40 changes: 32 additions & 8 deletions App_LocalResources/ucViewOptions.ascx.resx
Original file line number Diff line number Diff line change
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="ArticleSettings.Text" xml:space="preserve">
<value>Article Settings</value>
Expand Down Expand Up @@ -438,12 +438,6 @@
<data name="CommentSettings.Text" xml:space="preserve">
<value>Comment Settings</value>
</data>
<data name="UseCaptcha.Help" xml:space="preserve">
<value>Check to use captcha validation on the post comment screen.</value>
</data>
<data name="UseCaptcha.Text" xml:space="preserve">
<value>Use Captcha?</value>
</data>
<data name="EnableCommentModeration.Help" xml:space="preserve">
<value>Check to require comments to be moderated before posting.</value>
</data>
Expand Down Expand Up @@ -1197,4 +1191,34 @@
<data name="plJournalIntegrationGroups.Text" xml:space="preserve">
<value>Journal Group Posting</value>
</data>
<data name="CaptchaType.Help" xml:space="preserve">
<value>Select the type of captcha to use on the post comment screen.</value>
</data>
<data name="CaptchaType.Text" xml:space="preserve">
<value>Captcha Type</value>
</data>
<data name="CaptchaTypeDnnCore.Text" xml:space="preserve">
<value>Core DNN Captcha</value>
</data>
<data name="CaptchaTypeHoneypot.Text" xml:space="preserve">
<value>Use a Honepot control</value>
</data>
<data name="CaptchaTypeNone.Text" xml:space="preserve">
<value>None</value>
</data>
<data name="CaptchaTypeReCaptcha.Text" xml:space="preserve">
<value>Google reCaptcha</value>
</data>
<data name="reCaptchaSecretKey.Text" xml:space="preserve">
<value>reCaptcha Secret Key</value>
</data>
<data name="reCaptchaSiteKey.Text" xml:space="preserve">
<value>reCaptcha Site Key</value>
</data>
<data name="reCaptchaSecretKey.Help" xml:space="preserve">
<value>Google reCaptcha Secret Key, only needed when CaptchaType is set to reCaptcha.</value>
</data>
<data name="reCaptchaSiteKey.Help" xml:space="preserve">
<value>Google reCaptcha Site Key, only needed when CaptchaType is set to reCaptcha.</value>
</data>
</root>
41 changes: 34 additions & 7 deletions Components/ArticleSettings.vb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ Namespace Ventrian.NewsArticles
Dim role As String

For Each role In roles.Split(New Char() {";"c})
If (role <> "" AndAlso Not role Is Nothing AndAlso _
((context.Request.IsAuthenticated = False And role = glbRoleUnauthUserName) Or _
role = glbRoleAllUsersName Or _
objUserInfo.IsInRole(role) = True _
If (role <> "" AndAlso Not role Is Nothing AndAlso
((context.Request.IsAuthenticated = False And role = glbRoleUnauthUserName) Or
role = glbRoleAllUsersName Or
objUserInfo.IsInRole(role) = True
)) Then
Return True
End If
Expand Down Expand Up @@ -939,12 +939,39 @@ Namespace Ventrian.NewsArticles
End Get
End Property

Public ReadOnly Property UseCaptcha() As Boolean
Public ReadOnly Property CaptchaType() As CaptchaType
Get
Dim retval As CaptchaType = CaptchaType.None
If (Settings.Contains(ArticleConstants.USE_CAPTCHA_SETTING)) Then
Return Convert.ToBoolean(Settings(ArticleConstants.USE_CAPTCHA_SETTING))
'there's an existing module setting, so make sure we don't change behavior for that
If Convert.ToBoolean(Settings(ArticleConstants.USE_CAPTCHA_SETTING).ToString()) Then
retval = CaptchaType.DnnCore
End If
Else
Return False
If (Settings.Contains(ArticleConstants.CAPTCHATYPE_SETTING)) Then
retval = CType(System.Enum.Parse(GetType(CaptchaType), Settings(ArticleConstants.CAPTCHATYPE_SETTING)), CaptchaType)
End If
End If
Return retval
End Get
End Property

Public ReadOnly Property ReCaptchaSiteKey() As String
Get
If Settings.ContainsKey(ArticleConstants.RECAPTCHA_SITEKEY_SETTING) Then
Return Settings(ArticleConstants.RECAPTCHA_SITEKEY_SETTING).ToString()
Else
Return ""
End If
End Get
End Property

Public ReadOnly Property ReCaptchaSecretKey() As String
Get
If Settings.ContainsKey(ArticleConstants.RECAPTCHA_SECRETKEY_SETTING) Then
Return Settings(ArticleConstants.RECAPTCHA_SECRETKEY_SETTING).ToString()
Else
Return ""
End If
End Get
End Property
Expand Down
24 changes: 24 additions & 0 deletions Components/CaptchaType.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'
' News Articles for DotNetNuke - http://www.dotnetnuke.com
' Copyright (c) 2002-2007
' by Ventrian ( [email protected] ) ( http://www.ventrian.com )
'

Imports System
Imports System.Configuration
Imports System.Data

Imports DotNetNuke.Common.Utilities

Namespace Ventrian.NewsArticles

Public Enum CaptchaType

None
DnnCore
ReCaptcha
Honeypot

End Enum

End Namespace
3 changes: 3 additions & 0 deletions Components/Common/ArticleConstants.vb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ Namespace Ventrian.NewsArticles
Public Const COMMENT_REQUIRE_NAME_SETTING As String = "CommentRequireName"
Public Const COMMENT_REQUIRE_EMAIL_SETTING As String = "CommentRequireEmail"
Public Const USE_CAPTCHA_SETTING As String = "UseCaptcha"
Public Const CAPTCHATYPE_SETTING As String = "CaptchaType"
Public Const RECAPTCHA_SITEKEY_SETTING As String = "reCaptchaSiteKey"
Public Const RECAPTCHA_SECRETKEY_SETTING As String = "reCaptchaSecretKey"
Public Const NOTIFY_DEFAULT_SETTING As String = "NotifyDefault"
Public Const COMMENT_SORT_DIRECTION_SETTING As String = "CommentSortDirection"
Public Const COMMENT_AKISMET_SETTING As String = "CommentAkismet"
Expand Down
7 changes: 7 additions & 0 deletions Controls/Honeypot.ascx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Honeypot.ascx.vb" Inherits="Ventrian.NewsArticles.Controls.Honeypot" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<div style="display: none">
<dnn:Label ID="ConfirmEmailLabel" ControlName="txtConfirmEmail" runat="server" />
<asp:TextBox runat="server" ID="txtConfirmEmail"></asp:TextBox>
<asp:CustomValidator runat="server" CssClass="dnnFormMessage dnnFormError" ControlToValidate="txtConfirmEmail" ID="RecaptchaValidator" OnServerValidate="HoneypotValidator_OnServerValidate"/>
</div>
44 changes: 44 additions & 0 deletions Controls/Honeypot.ascx.designer.vb

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

23 changes: 23 additions & 0 deletions Controls/Honeypot.ascx.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Imports System.IO
Imports System.Net
Imports System.Web.Script.Serialization
Imports DotNetNuke.Common.Utilities

Namespace Ventrian.NewsArticles.Controls
Public Class Honeypot
Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub HoneypotValidator_OnServerValidate(source As Object, args As ServerValidateEventArgs)
args.IsValid = IsValid()
End Sub

Public Function IsValid() As Boolean
Return txtConfirmEmail.Text = ""
End Function
End Class

End Namespace
4 changes: 4 additions & 0 deletions Controls/PostComment.ascx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="PostComment.ascx.vb" Inherits="Ventrian.NewsArticles.Controls.PostComment" %>
<%@ Register TagPrefix="dnn" Assembly="DotNetNuke" Namespace="DotNetNuke.UI.WebControls"%>
<%@ Register TagPrefix="article" TagName="ReCaptcha" Src="ReCaptcha.ascx" %>
<%@ Register TagPrefix="article" TagName="Honeypot" Src="Honeypot.ascx" %>
<asp:PlaceHolder ID="phCommentForm" runat="Server">
<p id="pName" runat="server">
<asp:textbox id="txtName" cssclass="NormalTextBox" runat="server" />
Expand All @@ -25,6 +27,8 @@
controltovalidate="txtComment" errormessage="<br>Comment Is Required" display="Dynamic" SetFocusOnError="true" ValidationGroup="PostComment" />
</p>
<dnn:captchacontrol id="ctlCaptcha" captchawidth="130" captchaheight="40" cssclass="Normal" runat="server" errorstyle-cssclass="NormalRed" />
<article:ReCaptcha runat="server" id="ctlReCaptcha" />
<article:Honeypot runat="server" id="ctlHoneypot" />
<p>
<asp:Button ID="btnAddComment" runat="server" Text="Add Comment" ValidationGroup="PostComment" UseSubmitBehavior="False" />
</p>
Expand Down
Loading

0 comments on commit ab460a0

Please sign in to comment.