mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
Separating anonymous and authenticated comments and getting anonymous comments hooked up. Still a bit of work left in the comments space...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4046027
This commit is contained in:
@@ -128,41 +128,6 @@ namespace Orchard.Comments.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
return View(new CommentsCreateViewModel());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(string returnUrl) {
|
||||
var viewModel = new CommentsCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
if (CurrentSite.As<CommentSettings>().Record.RequireLoginToAddComment) {
|
||||
if (!_authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment")))
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
var context = new CreateCommentContext {
|
||||
Author = viewModel.Name,
|
||||
CommentText = viewModel.CommentText,
|
||||
Email = viewModel.Email,
|
||||
SiteName = viewModel.SiteName,
|
||||
CommentedOn = viewModel.CommentedOn,
|
||||
};
|
||||
|
||||
var comment = _commentService.CreateComment(context);
|
||||
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Creating Comment failed: " + exception.Message));
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Details(int id, CommentDetailsOptions options) {
|
||||
// Default options
|
||||
if (options == null)
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.Comments.Services;
|
||||
using Orchard.Comments.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Comments.Controllers {
|
||||
public class CommentController : Controller {
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly ICommentService _commentService;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public CommentController(ICommentService commentService, INotifier notifier, IAuthorizer authorizer) {
|
||||
_commentService = commentService;
|
||||
_notifier = notifier;
|
||||
_authorizer = authorizer;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
protected virtual IUser CurrentUser { get; [UsedImplicitly]
|
||||
private set; }
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly]
|
||||
private set; }
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(string returnUrl) {
|
||||
var viewModel = new CommentsCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
if (CurrentSite.As<CommentSettings>().Record.RequireLoginToAddComment) {
|
||||
if (!_authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment"))) {
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
}
|
||||
|
||||
var context = new CreateCommentContext {
|
||||
Author = viewModel.Name,
|
||||
CommentText = viewModel.CommentText,
|
||||
Email = viewModel.Email,
|
||||
SiteName = viewModel.SiteName,
|
||||
CommentedOn = viewModel.CommentedOn,
|
||||
};
|
||||
|
||||
Comment comment = _commentService.CreateComment(context);
|
||||
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Creating Comment failed: " + exception.Message));
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\CommentController.cs" />
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Models\ClosedCommentsRecord.cs" />
|
||||
<Compile Include="Models\Comment.cs" />
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Orchard.Comments.Services {
|
||||
comment.Record.CommentText = context.CommentText;
|
||||
comment.Record.Email = context.Email;
|
||||
comment.Record.SiteName = context.SiteName;
|
||||
comment.Record.UserName = (CurrentUser == null ? "Anonymous" : CurrentUser.UserName);
|
||||
comment.Record.UserName = (CurrentUser == null ? context.Author : CurrentUser.UserName);
|
||||
comment.Record.CommentedOn = context.CommentedOn;
|
||||
|
||||
comment.Record.Status = _commentValidator.ValidateComment(comment) ? CommentStatus.Pending : CommentStatus.Spam;
|
||||
|
||||
@@ -5,12 +5,12 @@ if (Model.Comments.Count > 0) { Html.RenderPartial("ListOfComments", Model.Comme
|
||||
if (Model.CommentsActive == false) { %>
|
||||
<p><%=_Encoded("Comments have been disabled for this content.") %></p><%
|
||||
} else { %>
|
||||
<%-- todo: (heskew) need a comment form for the authenticated user... --%>
|
||||
<% using(Html.BeginForm("Create", "Admin", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %>
|
||||
<% using(Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<fieldset class="who">
|
||||
<%=Html.Hidden("CommentedOn", Model.ContentItem.Id) %>
|
||||
<%=Html.Hidden("ReturnUrl", Context.Request.Url) %>
|
||||
<fieldset class="who"><%
|
||||
if (Request.IsAuthenticated) { %>
|
||||
<p><%=Html.Encode(Page.User.Identity.Name)%></p><%
|
||||
} else { %>
|
||||
<div>
|
||||
<label for="Name"><%=_Encoded("Name") %></label>
|
||||
<input id="Name" class="text" name="Name" type="text" />
|
||||
@@ -22,7 +22,8 @@ if (Model.CommentsActive == false) { %>
|
||||
<div>
|
||||
<label for="SiteName"><%=_Encoded("Url") %></label>
|
||||
<input id="SiteName" class="text" name="SiteName" type="text" />
|
||||
</div>
|
||||
</div><%
|
||||
} %>
|
||||
</fieldset>
|
||||
<fieldset class="what">
|
||||
<div>
|
||||
@@ -31,6 +32,8 @@ if (Model.CommentsActive == false) { %>
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit" class="button" value="<%=_Encoded("Submit Comment") %>" />
|
||||
<%=Html.Hidden("CommentedOn", Model.ContentItem.Id) %>
|
||||
<%=Html.Hidden("ReturnUrl", Context.Request.Url) %>
|
||||
<%=Html.AntiForgeryTokenOrchard() %>
|
||||
</div>
|
||||
</fieldset><%
|
||||
|
||||
Reference in New Issue
Block a user