Skip to content

Commit

Permalink
bugfix for comments and saving configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwm committed Mar 29, 2021
1 parent 5eccd86 commit 0641c1b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Akismet.Umbraco8/Akismet.Umbraco8/Akismet.Umbraco8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReleaseNotes>Got everything working; please report issues at https://github.com/ahwm/Akismet.Umbraco/issues </PackageReleaseNotes>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0</Version>
<Version>1.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions Akismet.Umbraco8/Akismet.Umbraco8/AkismetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ internal Dictionary<string, string> GetConfig()
return config;
}

internal void SetConfig(string key, string blogUrl)
{
string appData = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Plugins/akismet");
var config = new Dictionary<string, string> { { "key", key }, { "blogUrl", blogUrl } };
File.WriteAllText(Path.Combine(appData, "akismetConfig.json"), JsonConvert.SerializeObject(config));
}

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.");
}
});
}
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0641c1b

Please sign in to comment.