Added work context providers for the current site and user

--HG--
branch : theming
This commit is contained in:
Nathan Heskew
2010-09-13 18:27:42 -07:00
parent b368a0e5df
commit f4b7e29a07
7 changed files with 36 additions and 19 deletions

View File

@@ -3,7 +3,7 @@
<html lang="en" class="static @Html.ClassForPage()">
<head>
<meta charset="utf-8" />
<title>@Html.Title(Html.SiteName())</title>
<title>@Html.Title(WorkContext.CurrentSite.SiteName)</title>
@//could be a resource - at least need to get at the right location and this is something
<link rel="shortcut icon" type="image/x-icon" href="/modules/orchard.themes/Content/orchard.ico" />
@{

View File

@@ -1,4 +1,3 @@
@using Orchard.Mvc.Html
<header>
<h1>@Html.SiteName()</h1>
 <header>
<h1>@WorkContext.CurrentSite.SiteName</h1>
</header>

View File

@@ -1,10 +1,7 @@
@using System.Web.Mvc
@using Orchard.Security
@{ var user = Html.Resolve<IAuthenticationService>().GetAuthenticatedUser(); }
<div id="user-display">
@if (Request.IsAuthenticated) {
@T("Welcome, <strong>{0}</strong>!", user.UserName)
@T("Welcome, <strong>{0}</strong>!", WorkContext.CurrentUser.UserName)
@Html.ActionLink(T("Log Off").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl })
@:&#124; @Html.ActionLink("Admin", "Index", new {Area = "Dashboard", Controller = "Admin"})
} else {

View File

@@ -1,10 +0,0 @@
using System.Web.Mvc;
using Orchard.Settings;
namespace Orchard.Mvc.Html {
public static class SiteServiceExtensions {
public static string SiteName(this HtmlHelper html) {
return html.Resolve<ISiteService>().GetSiteSettings().SiteName;
}
}
}

View File

@@ -149,6 +149,8 @@
<Compile Include="Mvc\IOrchardViewPage.cs" />
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" />
<Compile Include="Security\CurrentUserWorkContext.cs" />
<Compile Include="Settings\CurrentSiteWorkContext.cs" />
<Compile Include="UI\Zones\PageWorkContext.cs" />
<Compile Include="UI\Zones\ZoneHoldingBehavior.cs" />
<Compile Include="Mvc\ViewEngines\ThemeAwareness\ConfiguredEnginesCache.cs" />
@@ -676,7 +678,6 @@
<Compile Include="Mvc\AntiForgery\AntiForgeryAuthorizationFilter.cs" />
<Compile Include="Mvc\Html\FileRegistrationContext.cs" />
<Compile Include="Mvc\Html\MvcFormAntiForgeryPost.cs" />
<Compile Include="Mvc\Html\SiteServiceExtensions.cs" />
<Compile Include="Tasks\Scheduling\IScheduledTaskHandler.cs" />
<Compile Include="Tasks\Scheduling\IScheduledTaskManager.cs" />
<Compile Include="Tasks\Scheduling\ScheduledTaskContext.cs" />

View File

@@ -0,0 +1,15 @@
namespace Orchard.Security {
public class CurrentUserWorkContext : IWorkContextStateProvider {
private readonly IAuthenticationService _authenticationService;
public CurrentUserWorkContext(IAuthenticationService authenticationService) {
_authenticationService = authenticationService;
}
public T Get<T>(string name) {
if (name == "CurrentUser")
return (T)_authenticationService.GetAuthenticatedUser();
return default(T);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Orchard.Settings {
public class CurrentSiteWorkContext : IWorkContextStateProvider {
private readonly ISiteService _siteService;
public CurrentSiteWorkContext(ISiteService siteService) {
_siteService = siteService;
}
public T Get<T>(string name) {
if (name == "CurrentSite")
return (T)_siteService.GetSiteSettings();
return default(T);
}
}
}