Ensuring remaining data-manipulating controller actions are POSTs

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045801
This commit is contained in:
skewed
2010-01-21 21:13:35 +00:00
parent fdae78826b
commit 910ca4f916
7 changed files with 73 additions and 34 deletions
@@ -129,7 +129,7 @@ namespace Orchard.Comments.Controllers {
return View(new CommentsCreateViewModel()); return View(new CommentsCreateViewModel());
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Create(string returnUrl) { public ActionResult Create(string returnUrl) {
var viewModel = new CommentsCreateViewModel(); var viewModel = new CommentsCreateViewModel();
try { try {
@@ -255,6 +255,7 @@ namespace Orchard.Comments.Controllers {
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
[HttpPost]
public ActionResult Close(int commentedItemId, string returnUrl) { public ActionResult Close(int commentedItemId, string returnUrl) {
try { try {
if (!_authorizer.Authorize(Permissions.CloseComment, T("Couldn't close comments"))) if (!_authorizer.Authorize(Permissions.CloseComment, T("Couldn't close comments")))
@@ -274,6 +275,7 @@ namespace Orchard.Comments.Controllers {
} }
} }
[HttpPost]
public ActionResult Enable(int commentedItemId, string returnUrl) { public ActionResult Enable(int commentedItemId, string returnUrl) {
try { try {
if (!_authorizer.Authorize(Permissions.EnableComment, T("Couldn't enable comments"))) if (!_authorizer.Authorize(Permissions.EnableComment, T("Couldn't enable comments")))
@@ -313,7 +315,7 @@ namespace Orchard.Comments.Controllers {
} }
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Edit(FormCollection input) { public ActionResult Edit(FormCollection input) {
var viewModel = new CommentsEditViewModel(); var viewModel = new CommentsEditViewModel();
try { try {
@@ -330,6 +332,7 @@ namespace Orchard.Comments.Controllers {
} }
} }
[HttpPost]
public ActionResult Delete(int id, string returnUrl) { public ActionResult Delete(int id, string returnUrl) {
try { try {
if (!_authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment"))) if (!_authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment")))
@@ -2,6 +2,21 @@
<%@ Import Namespace="Orchard.Comments.Models"%> <%@ Import Namespace="Orchard.Comments.Models"%>
<%@ Import Namespace="Orchard.Comments.ViewModels"%> <%@ Import Namespace="Orchard.Comments.ViewModels"%>
<h1><%=Html.TitleForPage(T("Comments for {0}", Model.DisplayNameForCommentedItem).ToString()) %></h1> <h1><%=Html.TitleForPage(T("Comments for {0}", Model.DisplayNameForCommentedItem).ToString()) %></h1>
<div class="manage"><%
if (Model.CommentsClosedOnItem) {
using (Html.BeginFormAntiForgeryPost(Url.Action("Enable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) { %>
<fieldset>
<button type="submit" title="<%=_Encoded("Enable Comments") %>"><%=_Encoded("Enable Comments")%></button>
</fieldset><%
}
} else {
using (Html.BeginFormAntiForgeryPost(Url.Action("Close", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) { %>
<fieldset>
<button type="submit" class="remove" title="<%=_Encoded("Close Comments") %>"><%=_Encoded("Close Comments")%></button>
</fieldset><%
}
} %>
</div>
<% using(Html.BeginFormAntiForgeryPost()) { %> <% using(Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %> <%=Html.ValidationSummary() %>
<fieldset class="actions bulk"> <fieldset class="actions bulk">
@@ -25,13 +40,6 @@
</select> </select>
<input class="button" type="submit" name="submit.Filter" value="<%=_Encoded("Apply") %>"/> <input class="button" type="submit" name="submit.Filter" value="<%=_Encoded("Apply") %>"/>
</fieldset> </fieldset>
<div class="manage">
<% if (Model.CommentsClosedOnItem) {
%><%=Html.ActionLink(T("Enable Comments").ToString(), "Enable", new { commentedItemId = Model.CommentedItemId }, new { @class = "button" })%><%
} else {
%><%=Html.ActionLink(T("Close Comments").ToString(), "Close", new { commentedItemId = Model.CommentedItemId }, new { @class = "button remove" })%><%
} %>
</div>
<fieldset> <fieldset>
<table class="items" summary="<%=_Encoded("This is a table of the comments for the content item") %>"> <table class="items" summary="<%=_Encoded("This is a table of the comments for the content item") %>">
<colgroup> <colgroup>
@@ -77,8 +85,18 @@
</td> </td>
<td><%=commentEntry.Comment.CommentDate.ToLocalTime() %></td> <td><%=commentEntry.Comment.CommentDate.ToLocalTime() %></td>
<td> <td>
<%=Html.ActionLink(T("Edit").ToString(), "Edit", new {commentEntry.Comment.Id}) %> | <ul class="actions">
<%=Html.ActionLink(T("Delete").ToString(), "Delete", new {id = commentEntry.Comment.Id, redirectToAction = "Details"}) %> <li class="construct">
<a href="<%=Url.Action("Edit", new {commentEntry.Comment.Id}) %>" class="ibutton edit" title="<%=_Encoded("Edit Comment")%>"><%=_Encoded("Edit Comment")%></a>
</li>
<li class="destruct">
<%-- a form in a form doesn't quite work <% using (Html.BeginFormAntiForgeryPost(Url.Action("Delete", new {id = commentEntry.Comment.Id, redirectToAction = "Details"}), FormMethod.Post, new { @class = "inline" })) { %>
<fieldset>
<button type="submit" class="ibutton remove" title="<%=_Encoded("Remove Comment") %>"><%=_Encoded("Remove Comment") %></button>
</fieldset><%
} %>
--%> </li>
</ul>
</td> </td>
</tr> </tr>
<% <%
@@ -86,11 +104,19 @@
} %> } %>
</table> </table>
</fieldset> </fieldset>
<div class="manage"> <% } %>
<% if (Model.CommentsClosedOnItem) { <div class="manage"><%
%><%=Html.ActionLink(T("Enable Comments").ToString(), "Enable", new { commentedItemId = Model.CommentedItemId }, new { @class = "button" })%><% if (Model.CommentsClosedOnItem) {
using (Html.BeginFormAntiForgeryPost(Url.Action("Enable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) { %>
<fieldset>
<button type="submit" title="<%=_Encoded("Enable Comments") %>"><%=_Encoded("Enable Comments")%></button>
</fieldset><%
}
} else { } else {
%><%=Html.ActionLink(T("Close Comments").ToString(), "Close", new { commentedItemId = Model.CommentedItemId }, new { @class = "button remove" })%><% using (Html.BeginFormAntiForgeryPost(Url.Action("Close", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) { %>
<fieldset>
<button type="submit" class="remove" title="<%=_Encoded("Close Comments") %>"><%=_Encoded("Close Comments")%></button>
</fieldset><%
}
} %> } %>
</div> </div>
<% } %>
@@ -70,8 +70,18 @@
<td><%=commentEntry.Comment.CommentDate.ToLocalTime() %></td> <td><%=commentEntry.Comment.CommentDate.ToLocalTime() %></td>
<td><%=Html.ActionLink(commentEntry.CommentedOn, "Details", new { id = commentEntry.Comment.CommentedOn }) %></td> <td><%=Html.ActionLink(commentEntry.CommentedOn, "Details", new { id = commentEntry.Comment.CommentedOn }) %></td>
<td> <td>
<%=Html.ActionLink(T("Edit").ToString(), "Edit", new {commentEntry.Comment.Id}) %> | <ul class="actions">
<%=Html.ActionLink(T("Delete").ToString(), "Delete", new { id = commentEntry.Comment.Id, redirectToAction = "Index" }) %> <li class="construct">
<a href="<%=Url.Action("Edit", new {commentEntry.Comment.Id}) %>" class="ibutton edit" title="<%=_Encoded("Edit Comment")%>"><%=_Encoded("Edit Comment")%></a>
</li>
<li class="destruct">
<%-- a form in a form doesn't quite work <% using (Html.BeginFormAntiForgeryPost(Url.Action("Delete", new {id = commentEntry.Comment.Id, redirectToAction = "Details"}), FormMethod.Post, new { @class = "inline" })) { %>
<fieldset>
<button type="submit" class="ibutton remove" title="<%=_Encoded("Remove Comment") %>"><%=_Encoded("Remove Comment") %></button>
</fieldset><%
} %>
--%> </li>
</ul>
</td> </td>
</tr> </tr>
<% <%
@@ -32,7 +32,7 @@ namespace Orchard.Media.Controllers {
return View(model); return View(model);
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Index(FormCollection input) { public ActionResult Index(FormCollection input) {
try { try {
foreach (string key in input.Keys) { foreach (string key in input.Keys) {
@@ -53,7 +53,7 @@ namespace Orchard.Media.Controllers {
return View(new MediaFolderCreateViewModel { MediaPath = mediaPath }); return View(new MediaFolderCreateViewModel { MediaPath = mediaPath });
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Create() { public ActionResult Create() {
var viewModel = new MediaFolderCreateViewModel(); var viewModel = new MediaFolderCreateViewModel();
try { try {
@@ -76,7 +76,7 @@ namespace Orchard.Media.Controllers {
return View(model); return View(model);
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Edit(FormCollection input) { public ActionResult Edit(FormCollection input) {
try { try {
foreach (string key in input.Keys) { foreach (string key in input.Keys) {
@@ -108,7 +108,7 @@ namespace Orchard.Media.Controllers {
return View(model); return View(model);
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult EditProperties() { public ActionResult EditProperties() {
var viewModel = new MediaFolderEditPropertiesViewModel(); var viewModel = new MediaFolderEditPropertiesViewModel();
try { try {
@@ -140,7 +140,7 @@ namespace Orchard.Media.Controllers {
return View(model); return View(model);
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Add() { public ActionResult Add() {
var viewModel = new MediaItemAddViewModel(); var viewModel = new MediaItemAddViewModel();
try { try {
@@ -172,7 +172,7 @@ namespace Orchard.Media.Controllers {
return View(model); return View(model);
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult EditMedia(FormCollection input) { public ActionResult EditMedia(FormCollection input) {
var viewModel = new MediaItemEditViewModel(); var viewModel = new MediaItemEditViewModel();
try { try {
@@ -116,7 +116,7 @@ namespace Orchard.Tags.Controllers {
} }
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Edit(FormCollection input) { public ActionResult Edit(FormCollection input) {
var viewModel = new TagsAdminEditViewModel(); var viewModel = new TagsAdminEditViewModel();
try { try {
@@ -42,7 +42,7 @@ namespace Orchard.Users.Controllers {
return View("LogOn", new LogOnViewModel { Title = "Log On", ReturnUrl = returnUrl }); return View("LogOn", new LogOnViewModel { Title = "Log On", ReturnUrl = returnUrl });
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")] Justification = "Needs to take same parameter type as Controller.Redirect()")]
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl) { public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl) {
@@ -79,7 +79,7 @@ namespace Orchard.Users.Controllers {
return View(new BaseViewModel()); return View(new BaseViewModel());
} }
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
public ActionResult Register(string userName, string email, string password, string confirmPassword) { public ActionResult Register(string userName, string email, string password, string confirmPassword) {
ViewData["PasswordLength"] = MinPasswordLength; ViewData["PasswordLength"] = MinPasswordLength;
@@ -109,7 +109,7 @@ namespace Orchard.Users.Controllers {
} }
[Authorize] [Authorize]
[AcceptVerbs(HttpVerbs.Post)] [HttpPost]
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "Exceptions result in password not being changed.")] Justification = "Exceptions result in password not being changed.")]
public ActionResult ChangePassword(string currentPassword, string newPassword, string confirmPassword) { public ActionResult ChangePassword(string currentPassword, string newPassword, string confirmPassword) {
@@ -293,7 +293,7 @@ a:hover, a:active, a:focus {
margin:-.4em 0 .4em; margin:-.4em 0 .4em;
} }
#main form { #main form {
margin:.345em 0 1.5em; margin:.345em 0 1.38em;
} }
#main form.inline { #main form.inline {
margin:0; margin:0;
@@ -360,7 +360,7 @@ form.inline fieldset {
fieldset.bulk.actions { fieldset.bulk.actions {
display:inline; display:inline;
height:auto; height:auto;
margin:0 1.4em -.7em 0; margin:0 1.4em 0 0;
padding-top:0; padding-top:0;
} }
@@ -488,7 +488,7 @@ button.remove:focus::-moz-focus-inner, .remove.button:focus::-moz-focus-inner {
} }
.manage { .manage {
float:right; float:right;
margin:4px 0 6px 4px; margin:0 0 10px 8px;
overflow:hidden; overflow:hidden;
} }
.actions { .actions {