- Comments: allow anonymous comments when the RequireLoginToAddComment setting is true.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041927
This commit is contained in:
suhacan
2009-11-23 19:44:33 +00:00
parent 990319a729
commit b9aeb675d0

View File

@@ -6,6 +6,7 @@ using System.Web.Mvc;
using Orchard.Comments.Models;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Models;
using Orchard.Settings;
using Orchard.UI.Notify;
using Orchard.Security;
@@ -113,15 +114,17 @@ namespace Orchard.Comments.Controllers {
var viewModel = new CommentsCreateViewModel();
try {
UpdateModel(viewModel, input.ToValueProvider());
if (!_authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment")))
return new HttpUnauthorizedResult();
if (CurrentSite.As<CommentSettings>().Record.RequireLoginToAddComment) {
if (!_authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment")))
return new HttpUnauthorizedResult();
}
Comment comment = new Comment {
Author = viewModel.Name,
CommentDate = DateTime.Now,
CommentText = viewModel.CommentText,
Email = viewModel.Email,
SiteName = viewModel.SiteName,
UserName = CurrentUser.UserName ?? "Anonymous",
UserName = CurrentUser == null ? "Anonymous" : CurrentUser.UserName,
CommentedOn = viewModel.CommentedOn
};
_commentService.CreateComment(comment);