mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding JavaScriptAntiSpamPart for JS-drive spam filtering
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using Orchard.AntiSpam.Models;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.AntiSpam.Drivers {
|
||||||
|
public class JavaScriptAntiSpamPartDriver : ContentPartDriver<JavaScriptAntiSpamPart> {
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public JavaScriptAntiSpamPartDriver() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(JavaScriptAntiSpamPart part, dynamic shapeHelper) {
|
||||||
|
return ContentShape("Parts_JavaScriptAntiSpam_Edit",
|
||||||
|
() => shapeHelper.EditorTemplate(
|
||||||
|
TemplateName: "Parts/Antispam.JavaScriptAntiSpam",
|
||||||
|
Model: part,
|
||||||
|
Prefix: Prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(JavaScriptAntiSpamPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
|
updater.TryUpdateModel(part, Prefix, null, null);
|
||||||
|
|
||||||
|
if (!part.IAmHuman) {
|
||||||
|
updater.AddModelError("NotHuman", T("You are either a bot (we only serve humans, sorry) or have JavaScript turned off. If the latter, please turn on JavaScript to post this form."));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Editor(part, shapeHelper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -10,10 +10,12 @@ namespace Orchard.AntiSpam {
|
|||||||
|
|
||||||
ContentDefinitionManager.AlterPartDefinition("SubmissionLimitPart", cfg => cfg
|
ContentDefinitionManager.AlterPartDefinition("SubmissionLimitPart", cfg => cfg
|
||||||
.Attachable()
|
.Attachable()
|
||||||
|
.WithDescription("Allows to filter content items based on submissions frequency.")
|
||||||
);
|
);
|
||||||
|
|
||||||
ContentDefinitionManager.AlterPartDefinition("ReCaptchaPart", cfg => cfg
|
ContentDefinitionManager.AlterPartDefinition("ReCaptchaPart", cfg => cfg
|
||||||
.Attachable()
|
.Attachable()
|
||||||
|
.WithDescription("Ensures content items are submitted by humans only.")
|
||||||
);
|
);
|
||||||
|
|
||||||
SchemaBuilder.CreateTable("ReCaptchaSettingsPartRecord",
|
SchemaBuilder.CreateTable("ReCaptchaSettingsPartRecord",
|
||||||
@@ -25,6 +27,7 @@ namespace Orchard.AntiSpam {
|
|||||||
|
|
||||||
ContentDefinitionManager.AlterPartDefinition("SpamFilterPart", cfg => cfg
|
ContentDefinitionManager.AlterPartDefinition("SpamFilterPart", cfg => cfg
|
||||||
.Attachable()
|
.Attachable()
|
||||||
|
.WithDescription("Allows to filter submitted content items based on spam filters.")
|
||||||
);
|
);
|
||||||
|
|
||||||
SchemaBuilder.CreateTable("SpamFilterPartRecord",
|
SchemaBuilder.CreateTable("SpamFilterPartRecord",
|
||||||
@@ -32,7 +35,12 @@ namespace Orchard.AntiSpam {
|
|||||||
.Column<string>("Status", c => c.WithLength(64))
|
.Column<string>("Status", c => c.WithLength(64))
|
||||||
);
|
);
|
||||||
|
|
||||||
return 2;
|
ContentDefinitionManager.AlterPartDefinition("JavaScriptAntiSpamPart",
|
||||||
|
builder => builder
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Prevents spambots to post the editor by requiring JavaScript support."));
|
||||||
|
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int UpdateFrom1() {
|
public int UpdateFrom1() {
|
||||||
@@ -59,6 +67,15 @@ namespace Orchard.AntiSpam {
|
|||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UpdateFrom3() {
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("JavaScriptAntiSpamPart",
|
||||||
|
builder => builder
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Prevents spambots to post the editor by requiring JavaScript support."));
|
||||||
|
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.AntiSpam.Models {
|
||||||
|
public class JavaScriptAntiSpamPart : ContentPart {
|
||||||
|
public bool IAmHuman { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@@ -10,7 +10,7 @@ Features:
|
|||||||
Name: Anti-Spam
|
Name: Anti-Spam
|
||||||
Description: Provides anti-spam services to protect your content from malicious submissions.
|
Description: Provides anti-spam services to protect your content from malicious submissions.
|
||||||
Category: Security
|
Category: Security
|
||||||
Dependencies: Orchard.Tokens
|
Dependencies: Orchard.Tokens, Orchard.jQuery
|
||||||
Akismet.Filter:
|
Akismet.Filter:
|
||||||
Name: Akismet Anti-Spam Filter
|
Name: Akismet Anti-Spam Filter
|
||||||
Description: Provides an anti-spam filter based on Akismet.
|
Description: Provides an anti-spam filter based on Akismet.
|
||||||
|
@@ -70,6 +70,8 @@
|
|||||||
<Content Include="Views\Web.config" />
|
<Content Include="Views\Web.config" />
|
||||||
<Content Include="Scripts\Web.config" />
|
<Content Include="Scripts\Web.config" />
|
||||||
<Content Include="Styles\Web.config" />
|
<Content Include="Styles\Web.config" />
|
||||||
|
<Compile Include="Drivers\JavaScriptAntiSpamPartDriver.cs" />
|
||||||
|
<Compile Include="Models\JavaScriptAntiSpamPart.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -166,6 +168,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\EditorTemplates\Parts\AntiSpam.ReCaptchaSettings.cshtml" />
|
<Content Include="Views\EditorTemplates\Parts\AntiSpam.ReCaptchaSettings.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\EditorTemplates\Parts\Antispam.JavaScriptAntiSpam.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
@@ -7,4 +7,5 @@
|
|||||||
|
|
||||||
<Place Parts_AntiSpam_AkismetSettings="Content:9"/>
|
<Place Parts_AntiSpam_AkismetSettings="Content:9"/>
|
||||||
<Place Parts_AntiSpam_TypePadSettings="Content:10"/>
|
<Place Parts_AntiSpam_TypePadSettings="Content:10"/>
|
||||||
|
<Place Parts_JavaScriptAntiSpam_Edit="Content:5"/>
|
||||||
</Placement>
|
</Placement>
|
||||||
|
@@ -0,0 +1,19 @@
|
|||||||
|
@model Orchard.AntiSpam.Models.JavaScriptAntiSpamPart
|
||||||
|
|
||||||
|
@{
|
||||||
|
Script.Require("jQuery").AtFoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Html.HiddenFor(m => m.IAmHuman)
|
||||||
|
|
||||||
|
@using (Script.Foot()) {
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function ($) {
|
||||||
|
var $field = $("#@Html.FieldIdFor(m => m.IAmHuman)");
|
||||||
|
|
||||||
|
$field.closest("form").submit(function () {
|
||||||
|
$field.val("True");
|
||||||
|
});
|
||||||
|
})(jQuery);
|
||||||
|
</script>
|
||||||
|
}
|
Reference in New Issue
Block a user