From 0641c1b244154c6ec1f46cb03c5135dda5d5770f Mon Sep 17 00:00:00 2001 From: Adam Humpherys Date: Mon, 29 Mar 2021 11:56:01 -0600 Subject: [PATCH] bugfix for comments and saving configuration --- .../Akismet.Umbraco8/Akismet.Umbraco8.csproj | 2 +- .../Akismet.Umbraco8/AkismetService.cs | 7 +++++++ .../App_Plugins/akismet/akismet.controller.js | 6 +++--- .../Controllers/AkismetApiController.cs | 16 +++++++++++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Akismet.Umbraco8/Akismet.Umbraco8/Akismet.Umbraco8.csproj b/Akismet.Umbraco8/Akismet.Umbraco8/Akismet.Umbraco8.csproj index a343b63..ca4c1a3 100644 --- a/Akismet.Umbraco8/Akismet.Umbraco8/Akismet.Umbraco8.csproj +++ b/Akismet.Umbraco8/Akismet.Umbraco8/Akismet.Umbraco8.csproj @@ -13,7 +13,7 @@ Got everything working; please report issues at https://github.com/ahwm/Akismet.Umbraco/issues true true - 1.0 + 1.0.1 diff --git a/Akismet.Umbraco8/Akismet.Umbraco8/AkismetService.cs b/Akismet.Umbraco8/Akismet.Umbraco8/AkismetService.cs index 97b2c77..f558c48 100644 --- a/Akismet.Umbraco8/Akismet.Umbraco8/AkismetService.cs +++ b/Akismet.Umbraco8/Akismet.Umbraco8/AkismetService.cs @@ -28,6 +28,13 @@ internal Dictionary GetConfig() return config; } + internal void SetConfig(string key, string blogUrl) + { + string appData = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Plugins/akismet"); + var config = new Dictionary { { "key", key }, { "blogUrl", blogUrl } }; + File.WriteAllText(Path.Combine(appData, "akismetConfig.json"), JsonConvert.SerializeObject(config)); + } + /// /// /// diff --git a/Akismet.Umbraco8/Akismet.Umbraco8/App_Plugins/akismet/akismet.controller.js b/Akismet.Umbraco8/Akismet.Umbraco8/App_Plugins/akismet/akismet.controller.js index 5ff39c9..8feb9a4 100644 --- a/Akismet.Umbraco8/Akismet.Umbraco8/App_Plugins/akismet/akismet.controller.js +++ b/Akismet.Umbraco8/Akismet.Umbraco8/App_Plugins/akismet/akismet.controller.js @@ -184,7 +184,7 @@ angular.module("umbraco").controller("AkismetConfigController", function ($scope if (blogUrl.trim().length < 1 && valid) { vm.buttonState = "error"; valid = false; - notificationsService.error("URL invalid - must be your site's home page"); + notificationsService.error("URL invalid - it should be your site's home page"); } if (valid) { @@ -200,7 +200,7 @@ angular.module("umbraco").controller("AkismetConfigController", function ($scope notificationsService.success("API key saved. Return to the overview to see more information."); } else { vm.buttonState = "error"; - notificationsService.error("API key invalid"); + notificationsService.error("API key invalid or another error occurred while saving the configuration. Ensure the key is accurate and that App_Plugins/akismet has write permissions."); } }); } @@ -226,7 +226,7 @@ angular.module("umbraco").controller("AkismetConfigController", function ($scope } }); -angular.module("umbraco").controller("AkismetCommentsController", function ($scope, $http, notificationsService, listViewHelper) { +angular.module("umbraco").controller("AkismetCommentsController", function ($scope, $http, notificationsService, listViewHelper, overlayService) { var vm = this; vm.page = { name: "Comments" diff --git a/Akismet.Umbraco8/Akismet.Umbraco8/Controllers/AkismetApiController.cs b/Akismet.Umbraco8/Akismet.Umbraco8/Controllers/AkismetApiController.cs index 934f560..58a15fa 100644 --- a/Akismet.Umbraco8/Akismet.Umbraco8/Controllers/AkismetApiController.cs +++ b/Akismet.Umbraco8/Akismet.Umbraco8/Controllers/AkismetApiController.cs @@ -45,7 +45,21 @@ public bool VerifyKey(string key, string blogUrl) return false; AkismetClient client = new AkismetClient(key, new Uri(blogUrl), "Umbraco CMS"); - return client.VerifyKey(); + bool isValid = client.VerifyKey(); + if (isValid) + { + try + { + AkismetService.SetConfig(key, blogUrl); + return true; + } + catch + { + return false; + } + } + + return false; } public int GetSpamCommentPageCount()