mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 21:02:08 +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");
|
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) {
|
public ActionResult Details(int id, CommentDetailsOptions options) {
|
||||||
// Default options
|
// Default options
|
||||||
if (options == null)
|
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>
|
<ItemGroup>
|
||||||
<Compile Include="AdminMenu.cs" />
|
<Compile Include="AdminMenu.cs" />
|
||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
|
<Compile Include="Controllers\CommentController.cs" />
|
||||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||||
<Compile Include="Models\ClosedCommentsRecord.cs" />
|
<Compile Include="Models\ClosedCommentsRecord.cs" />
|
||||||
<Compile Include="Models\Comment.cs" />
|
<Compile Include="Models\Comment.cs" />
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace Orchard.Comments.Services {
|
|||||||
comment.Record.CommentText = context.CommentText;
|
comment.Record.CommentText = context.CommentText;
|
||||||
comment.Record.Email = context.Email;
|
comment.Record.Email = context.Email;
|
||||||
comment.Record.SiteName = context.SiteName;
|
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.CommentedOn = context.CommentedOn;
|
||||||
|
|
||||||
comment.Record.Status = _commentValidator.ValidateComment(comment) ? CommentStatus.Pending : CommentStatus.Spam;
|
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) { %>
|
if (Model.CommentsActive == false) { %>
|
||||||
<p><%=_Encoded("Comments have been disabled for this content.") %></p><%
|
<p><%=_Encoded("Comments have been disabled for this content.") %></p><%
|
||||||
} else { %>
|
} else { %>
|
||||||
<%-- todo: (heskew) need a comment form for the authenticated user... --%>
|
<% using(Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %>
|
||||||
<% using(Html.BeginForm("Create", "Admin", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %>
|
|
||||||
<%=Html.ValidationSummary() %>
|
<%=Html.ValidationSummary() %>
|
||||||
<fieldset class="who">
|
<fieldset class="who"><%
|
||||||
<%=Html.Hidden("CommentedOn", Model.ContentItem.Id) %>
|
if (Request.IsAuthenticated) { %>
|
||||||
<%=Html.Hidden("ReturnUrl", Context.Request.Url) %>
|
<p><%=Html.Encode(Page.User.Identity.Name)%></p><%
|
||||||
|
} else { %>
|
||||||
<div>
|
<div>
|
||||||
<label for="Name"><%=_Encoded("Name") %></label>
|
<label for="Name"><%=_Encoded("Name") %></label>
|
||||||
<input id="Name" class="text" name="Name" type="text" />
|
<input id="Name" class="text" name="Name" type="text" />
|
||||||
@@ -22,7 +22,8 @@ if (Model.CommentsActive == false) { %>
|
|||||||
<div>
|
<div>
|
||||||
<label for="SiteName"><%=_Encoded("Url") %></label>
|
<label for="SiteName"><%=_Encoded("Url") %></label>
|
||||||
<input id="SiteName" class="text" name="SiteName" type="text" />
|
<input id="SiteName" class="text" name="SiteName" type="text" />
|
||||||
</div>
|
</div><%
|
||||||
|
} %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="what">
|
<fieldset class="what">
|
||||||
<div>
|
<div>
|
||||||
@@ -31,6 +32,8 @@ if (Model.CommentsActive == false) { %>
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="submit" class="button" value="<%=_Encoded("Submit Comment") %>" />
|
<input type="submit" class="button" value="<%=_Encoded("Submit Comment") %>" />
|
||||||
|
<%=Html.Hidden("CommentedOn", Model.ContentItem.Id) %>
|
||||||
|
<%=Html.Hidden("ReturnUrl", Context.Request.Url) %>
|
||||||
<%=Html.AntiForgeryTokenOrchard() %>
|
<%=Html.AntiForgeryTokenOrchard() %>
|
||||||
</div>
|
</div>
|
||||||
</fieldset><%
|
</fieldset><%
|
||||||
|
|||||||
Reference in New Issue
Block a user