From 3ebdb0019c0886e60702c5e67530c7a04141067f Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 2 Mar 2010 06:33:12 -0800 Subject: [PATCH] Cleaning up the "add comment" UI - If the user is not authenticated and doesn't have permission to add a comment a message is given for them to "log on" - "log on" link to add a comment hashed appropriately so the browser drops down to the comment form on return after logging on - Updated the default User template to give the log off link a return URL and updated the AccountController to do the same redirect to the given location, if given, on action completion so the user is returned to the same location they left. The "log off" link in an admin theme should never include a return URL because the resulting experience would be bad (they'd be sent back to the log on page with a not authorized message) --HG-- branch : dev --- src/Orchard.Web/Core/Themes/Views/User.ascx | 2 +- .../Parts/Comments.HasComments.ascx | 15 ++++++++++++--- .../Controllers/AccountController.cs | 15 +++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Orchard.Web/Core/Themes/Views/User.ascx b/src/Orchard.Web/Core/Themes/Views/User.ascx index 2baa90434..7ae17a794 100644 --- a/src/Orchard.Web/Core/Themes/Views/User.ascx +++ b/src/Orchard.Web/Core/Themes/Views/User.ascx @@ -3,7 +3,7 @@
<% if (Request.IsAuthenticated) { %> <%=T("Welcome, {0}!", Html.Encode(Page.User.Identity.Name)) %> - <%=Html.ActionLink(T("Log Off").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users" })%> + <%=Html.ActionLink(T("Log Off").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl })%>  | <%= Html.ActionLink("Admin", "Index", new {Area = "Dashboard", Controller = "Admin"})%> <% } else { %> <%=Html.ActionLink(T("Log On").ToString(), "LogOn", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl }) %> diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/DisplayTemplates/Parts/Comments.HasComments.ascx b/src/Orchard.Web/Modules/Orchard.Comments/Views/DisplayTemplates/Parts/Comments.HasComments.ascx index 102e41dec..49d4a3c35 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/DisplayTemplates/Parts/Comments.HasComments.ascx +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/DisplayTemplates/Parts/Comments.HasComments.ascx @@ -1,17 +1,26 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Comments"%> <%@ Import Namespace="Orchard.Security" %> -<%@ Import Namespace="Orchard.Comments.Models" %><% +<%@ Import Namespace="Orchard.Comments.Models" %> +<%-- todo: clean up this template - waaay too much going on in here :/ --%><% if (Model.Comments.Count > 0) { %> -

<%=_Encoded("{0} Comment{1}", Model.Comments.Count, Model.Comments.Count == 1 ? "" : "s")%>

<% Html.RenderPartial("ListOfComments", Model.Comments); } +

<%=_Encoded("{0} Comment{1}", Model.Comments.Count, Model.Comments.Count == 1 ? "" : "s")%>

+<% Html.RenderPartial("ListOfComments", Model.Comments); +} + if (Model.CommentsActive == false) { if (Model.Comments.Count > 0) { %>

<%=_Encoded("Comments have been disabled for this content.") %>

<% } } +else if(!Request.IsAuthenticated && !AuthorizedFor(Permissions.AddComment)) { %> +

<%=_Encoded("Add a Comment") %>

+

<%=T("You must {0} to comment.", Html.ActionLink(T("log on").ToString(), "LogOn", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = string.Format("{0}#addacomment", Context.Request.RawUrl) }))%>

<% +} else { %> <% using (Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %> <%=Html.ValidationSummary() %> -

<%=_Encoded("Add a Comment") %>

<% +

<%=_Encoded("Add a Comment") %>

<% if (!Request.IsAuthenticated) { %>
diff --git a/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs b/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs index 5e21b7abe..b2c922b22 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs +++ b/src/Orchard.Web/Modules/Orchard.Users/Controllers/AccountController.cs @@ -53,18 +53,17 @@ namespace Orchard.Users.Controllers { _authenticationService.SignIn(user, rememberMe); - if (!String.IsNullOrEmpty(returnUrl)) { - return Redirect(returnUrl); - } - else { - return Redirect("~/"); - } + return !String.IsNullOrEmpty(returnUrl) + ? Redirect(returnUrl) + : Redirect("~/"); } - public ActionResult LogOff() { + public ActionResult LogOff(string returnUrl) { _authenticationService.SignOut(); - return Redirect("~/"); + return !String.IsNullOrEmpty(returnUrl) + ? Redirect(returnUrl) + : Redirect("~/"); } int MinPasswordLength {