Adding Orchard.MultiTenancy

--HG--
branch : dev
This commit is contained in:
Louis DeJardin 2010-09-14 18:26:06 -07:00
parent 1ea5c25c1a
commit 2d5adfc0f1
21 changed files with 192 additions and 171 deletions

View File

@ -0,0 +1,11 @@
name: MultiTenancy
antiforgery: enabled
author: The Orchard Team
website: http://orchardproject.net
version: 0.5.0
orchardversion: 0.5.0
description: The multi-tenancy module enables multiple Orchard sites to run in isolation inside of a single web application, improving site density on a single server or hosted account.
features:
Orchard.MultiTenancy:
Description: Configure multiple site tenants.
Category: Hosting

View File

@ -83,13 +83,13 @@
<Content Include="Content\Admin\images\enabled.gif" />
<Content Include="Module.txt" />
<Content Include="Styles\admin.css" />
<Content Include="Views\Admin\Add.ascx" />
<Content Include="Views\Admin\Edit.ascx" />
<Content Include="Views\Admin\DisplayTemplates\ActionsForUninitialized.ascx" />
<Content Include="Views\Admin\DisplayTemplates\ActionsForDisabled.ascx" />
<Content Include="Views\Admin\DisplayTemplates\ActionsForInvalid.ascx" />
<Content Include="Views\Admin\DisplayTemplates\ActionsForRunning.ascx" />
<Content Include="Views\Admin\Index.ascx" />
<None Include="Views\Admin\Add.cshtml" />
<None Include="Views\Admin\Edit.cshtml" />
<None Include="Views\Admin\DisplayTemplates\ActionsForUninitialized.cshtml" />
<None Include="Views\Admin\DisplayTemplates\ActionsForDisabled.cshtml" />
<None Include="Views\Admin\DisplayTemplates\ActionsForInvalid.cshtml" />
<None Include="Views\Admin\DisplayTemplates\ActionsForRunning.cshtml" />
<None Include="Views\Admin\Index.cshtml" />
<Content Include="Web.config" />
<Content Include="Views\Web.config" />
</ItemGroup>

View File

@ -1,9 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Orchard.MultiTenancy.Annotations;
using Orchard.Mvc.ViewModels;
namespace Orchard.MultiTenancy.ViewModels {
public class TenantAddViewModel : BaseViewModel {
public class TenantAddViewModel {
[Required]
public string Name { get; set; }
public string RequestUrlHost { get; set; }

View File

@ -1,11 +1,9 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Orchard.Environment.Configuration;
using Orchard.MultiTenancy.Annotations;
using Orchard.Mvc.ViewModels;
namespace Orchard.MultiTenancy.ViewModels {
public class TenantEditViewModel : BaseViewModel {
public class TenantEditViewModel {
[Required]
public string Name { get; set; }
public string RequestUrlHost { get; set; }

View File

@ -1,9 +1,8 @@
using System.Collections.Generic;
using Orchard.Environment.Configuration;
using Orchard.Mvc.ViewModels;
namespace Orchard.MultiTenancy.ViewModels {
public class TenantsIndexViewModel : BaseViewModel {
public class TenantsIndexViewModel {
public IEnumerable<ShellSettings> TenantSettings { get; set; }
}
}

View File

@ -1,47 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantAddViewModel>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
<h1><%: Html.TitleForPage(T("Add New Tenant").ToString()) %></h1>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%: Html.ValidationSummary() %>
<fieldset>
<div>
<label for="Name"><%: T("Name") %></label>
<input id="Name" class="textMedium" name="Name" type="text" />
</div>
<div>
<label for="RequestUrlHost"><%: T("Host") %></label>
<input id="RequestUrlHost" class="textMedium" name="RequestUrlHost" type="text" />
<span class="hint"><%: T("Example: If host is 'orchardproject.net', the tenant site URL is 'http://orchardproject.net/'") %></span>
</div>
</fieldset>
<fieldset>
<legend><%: T("Database Setup") %></legend>
<div>
<%: Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })%>
<label for="tenantDatabaseOption" class="forcheckbox"><%: T("Allow the tenant to set up the database") %></label>
</div>
<div>
<%: Html.RadioButtonFor(svm => svm.DataProvider, "SqlCe", new { id = "builtinDatabaseOption" })%>
<label for="builtinDatabaseOption" class="forcheckbox"><%: T("Use built-in data storage (SQL Server Compact)") %></label>
</div>
<div>
<%: Html.RadioButtonFor(svm => svm.DataProvider, "SqlServer", new { id = "sqlDatabaseOption" })%>
<label for="sqlDatabaseOption" class="forcheckbox"><%: T("Use an existing SQL Server (or SQL Express) database") %></label>
<div class="options">
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseConnectionString"><%: T("Connection string") %></label>
<%: Html.EditorFor(svm => svm.DatabaseConnectionString)%>
<span class="hint"><%: T("Example:") %> <%: T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password") %></span>
</span>
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseTablePrefix"><%: T("Database Table Prefix") %></label>
<%: Html.EditorFor(svm => svm.DatabaseTablePrefix)%>
</span>
</div>
</div>
</fieldset>
<fieldset>
<input type="submit" class="button primaryAction" value="<%: T("Save") %>" />
</fieldset>
<% } %>

View File

@ -0,0 +1,46 @@
@model Orchard.MultiTenancy.ViewModels.TenantAddViewModel
<h1>@Html.TitleForPage(T("Add New Tenant").ToString())</h1>
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<fieldset>
<div>
<label for="Name">@T("Name")</label>
<input id="Name" class="textMedium" name="Name" type="text" />
</div>
<div>
<label for="RequestUrlHost">@T("Host")</label>
<input id="RequestUrlHost" class="textMedium" name="RequestUrlHost" type="text" />
<span class="hint">@T("Example: If host is 'orchardproject.net', the tenant site URL is 'http://orchardproject.net/'")</span>
</div>
</fieldset>
<fieldset>
<legend>@T("Database Setup")</legend>
<div>
@Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })
<label for="tenantDatabaseOption" class="forcheckbox">@T("Allow the tenant to set up the database")</label>
</div>
<div>
@Html.RadioButtonFor(svm => svm.DataProvider, "SqlCe", new { id = "builtinDatabaseOption" })
<label for="builtinDatabaseOption" class="forcheckbox">@T("Use built-in data storage (SQL Server Compact)")</label>
</div>
<div>
@Html.RadioButtonFor(svm => svm.DataProvider, "SqlServer", new { id = "sqlDatabaseOption" })
<label for="sqlDatabaseOption" class="forcheckbox">@T("Use an existing SQL Server (or SQL Express) database")</label>
<div class="options">
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseConnectionString">@T("Connection string")</label>
@Html.EditorFor(svm => svm.DatabaseConnectionString)
<span class="hint">@T("Example:") @T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")</span>
</span>
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseTablePrefix">@T("Database Table Prefix")</label>
@Html.EditorFor(svm => svm.DatabaseTablePrefix)
</span>
</div>
</div>
</fieldset>
<fieldset>
<input type="submit" class="button primaryAction" value="@T("Save")" />
</fieldset>
}

View File

@ -1,6 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ShellSettings>" %>
<%@ Import Namespace="Orchard.Environment.Configuration" %>
<% using(Html.BeginFormAntiForgeryPost(Url.Action("enable", new {area = "Orchard.MultiTenancy"}), FormMethod.Post, new {@class = "inline link"})) { %>
<%: Html.HiddenFor(ss => ss.Name) %>
<button type="submit"><%: T("Resume")%></button><%
} %>

View File

@ -0,0 +1,7 @@
@model Orchard.Environment.Configuration.ShellSettings
@using Orchard.MultiTenancy.Extensions
@using(Html.BeginFormAntiForgeryPost(Url.Action("enable", new {area = "Orchard.MultiTenancy"}), FormMethod.Post, new {@class = "inline link"})) {
@Html.HiddenFor(ss => ss.Name)
<button type="submit">@T("Resume")</button>
}

View File

@ -1,3 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ShellSettings>" %>
<%@ Import Namespace="Orchard.Environment.Configuration" %>
<%: Html.ActionLink(T("Make Valid*").ToString(), "_setup", new {tenantName = Model.Name, area = "Orchard.MultiTenancy"}) %>

View File

@ -0,0 +1,4 @@
@model Orchard.Environment.Configuration.ShellSettings
@using Orchard.MultiTenancy.Extensions
@Html.ActionLink(T("Make Valid*").ToString(), "_setup", new {tenantName = Model.Name, area = "Orchard.MultiTenancy"})

View File

@ -1,6 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ShellSettings>" %>
<%@ Import Namespace="Orchard.Environment.Configuration" %>
<% using(Html.BeginFormAntiForgeryPost(Url.Action("disable", new {area = "Orchard.MultiTenancy"}), FormMethod.Post, new {@class = "inline link"})) { %>
<%: Html.HiddenFor(ss => ss.Name) %>
<button type="submit"><%: T("Suspend") %></button><%
} %>

View File

@ -0,0 +1,7 @@
@model Orchard.Environment.Configuration.ShellSettings
@using Orchard.MultiTenancy.Extensions
@using(Html.BeginFormAntiForgeryPost(Url.Action("disable", new {area = "Orchard.MultiTenancy"}), FormMethod.Post, new {@class = "inline link"})) {
@Html.HiddenFor(ss => ss.Name)
<button type="submit">@T("Suspend")</button>
}

View File

@ -1,5 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ShellSettings>" %>
<%@ Import Namespace="Orchard.MultiTenancy.Extensions"%>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Environment.Configuration" %>
<%: Html.Link(T("Set Up").ToString(), Url.Tenant(Model))%>

View File

@ -0,0 +1,4 @@
@model Orchard.Environment.Configuration.ShellSettings
@using Orchard.MultiTenancy.Extensions
@Html.Link(T("Set Up").ToString(), Url.Tenant(Model))

View File

@ -1,49 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantEditViewModel>" %>
<%@ Import Namespace="Orchard.Environment.Configuration" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
<h1><%: Html.TitleForPage(T("Edit Tenant").ToString()) %></h1>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%: Html.ValidationSummary() %>
<fieldset>
<div>
<h2><%: Model.Name %></h2>
</div>
<div>
<label for="RequestUrlHost"><%: T("Host") %></label>
<%: Html.TextBoxFor(m => m.RequestUrlHost, new {@class = "textMedium"}) %>
<span class="hint"><%: T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"") %></span>
</div>
</fieldset>
<fieldset>
<legend><%: T("Database Setup") %></legend><%
if (Model.State.CurrentState != TenantState.State.Uninitialized) { %>
<div class="warning message"><%: T("Warning: If you don't know what you're doing you *will* (likely) send this tenant into a downward spiral of irrecoverable disrepair. Have a nice day.")%></div><%
} else { %>
<div>
<%: Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })%>
<label for="tenantDatabaseOption" class="forcheckbox"><%: T("Allow the tenant to set up the database") %></label>
</div><%
} %>
<div>
<%: Html.RadioButtonFor(svm => svm.DataProvider, "SqlCe", new { id = "builtinDatabaseOption" })%>
<label for="builtinDatabaseOption" class="forcheckbox"><%: T("Use built-in data storage (SQL Server Compact)") %></label>
</div>
<div>
<%: Html.RadioButtonFor(svm => svm.DataProvider, "SqlServer", new { id = "sqlDatabaseOption" })%>
<label for="sqlDatabaseOption" class="forcheckbox"><%: T("Use an existing SQL Server (or SQL Express) database") %></label>
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseConnectionString"><%: T("Connection string") %></label>
<%: Html.TextBoxFor(svm => svm.DatabaseConnectionString, new {@class = "large text"})%>
<span class="hint"><%: T("Example:") %><br /><%: T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password") %></span>
</span>
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseTablePrefix"><%: T("Database Table Prefix") %></label>
<%: Html.EditorFor(svm => svm.DatabaseTablePrefix)%>
</span>
</div>
</fieldset>
<fieldset>
<input type="submit" class="button primaryAction" value="<%: T("Save") %>" />
</fieldset>
<% } %>

View File

@ -0,0 +1,48 @@
@model Orchard.MultiTenancy.ViewModels.TenantEditViewModel
@using Orchard.Environment.Configuration
<h1>@Html.TitleForPage(T("Edit Tenant").ToString())</h1>
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<fieldset>
<div>
<h2>@Model.Name</h2>
</div>
<div>
<label for="RequestUrlHost">@T("Host")</label>
@Html.TextBoxFor(m => m.RequestUrlHost, new {@class = "textMedium"})
<span class="hint">@T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"")</span>
</div>
</fieldset>
<fieldset>
<legend>@T("Database Setup")</legend>
@if (Model.State.CurrentState != TenantState.State.Uninitialized) {
<div class="warning message">@T("Warning: If you don't know what you're doing you *will* (likely) send this tenant into a downward spiral of irrecoverable disrepair. Have a nice day.")</div>
} else {
<div>
@Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })
<label for="tenantDatabaseOption" class="forcheckbox">@T("Allow the tenant to set up the database")</label>
</div>
}
<div>
@Html.RadioButtonFor(svm => svm.DataProvider, "SqlCe", new { id = "builtinDatabaseOption" })
<label for="builtinDatabaseOption" class="forcheckbox">@T("Use built-in data storage (SQL Server Compact)")</label>
</div>
<div>
@Html.RadioButtonFor(svm => svm.DataProvider, "SqlServer", new { id = "sqlDatabaseOption" })
<label for="sqlDatabaseOption" class="forcheckbox">@T("Use an existing SQL Server (or SQL Express) database")</label>
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseConnectionString">@T("Connection string")</label>
@Html.TextBoxFor(svm => svm.DatabaseConnectionString, new {@class = "large text"})
<span class="hint">@T("Example:")<br />@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")</span>
</span>
<span data-controllerid="sqlDatabaseOption">
<label for="DatabaseTablePrefix">@T("Database Table Prefix")</label>
@Html.EditorFor(svm => svm.DatabaseTablePrefix)
</span>
</div>
</fieldset>
<fieldset>
<input type="submit" class="button primaryAction" value="@T("Save")" />
</fieldset>
}

View File

@ -1,33 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantsIndexViewModel>" %>
<%@ Import Namespace="Orchard.MultiTenancy.Extensions" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
<%Html.RegisterStyle("admin.css"); %>
<h1><%: Html.TitleForPage(T("List of Site's Tenants").ToString())%></h1>
<div class="manage"><%: Html.ActionLink(T("Add a Tenant").ToString(), "Add", new {area = "Orchard.MultiTenancy"}, new { @class = "button primaryAction" })%></div>
<ul class="contentItems tenants"><%
foreach (var tenant in Model.TenantSettings) { %>
<li class="tenant <%=tenant.State.CurrentState %>">
<div class="summary">
<div class="properties">
<h3><%: tenant.Name %><%
if (!string.IsNullOrEmpty(tenant.RequestUrlHost)) {
%><span class="tenantHost"> - <%: Html.Link(Url.Tenant(tenant), Url.Tenant(tenant))%></span><%
} %></h3>
</div>
<div class="related"><%
if (!string.Equals(tenant.Name, "default", StringComparison.OrdinalIgnoreCase)) { //todo: (heskew) base this off the view model so logic on what can be removed and have its state changed stays in the controller
var t = tenant; %>
<%: Html.DisplayFor(m => t, string.Format("ActionsFor{0}", tenant.State.CurrentState), "") %><%: T(" | ")%><%
} %>
<%: Html.ActionLink(T("Edit").ToString(), "Edit", new {name = tenant.Name, area = "Orchard.MultiTenancy"}) %><%
if (!string.Equals(tenant.Name, "default", StringComparison.OrdinalIgnoreCase)) { //todo: (heskew) base this off the view model so logic on what can be removed and have its state changed stays in the controller
%><%--
delete not implemented! <%: T(" | ")%>
<%: Html.ActionLink(T("Remove").ToString(), "delete", new {tenantName = tenant.Name, area = "Orchard.MultiTenancy"}) %>--%><%
} %>
</div>
</div>
</li><%
} %>
</ul>

View File

@ -0,0 +1,30 @@
@model Orchard.MultiTenancy.ViewModels.TenantsIndexViewModel
@using Orchard.MultiTenancy.Extensions
@{
Html.RegisterStyle("admin.css");
}
<h1>@Html.TitleForPage(T("List of Site's Tenants").ToString())</h1>
<div class="manage">@Html.ActionLink(T("Add a Tenant").ToString(), "Add", new {area = "Orchard.MultiTenancy"}, new { @class = "button primaryAction" })</div>
<ul class="contentItems tenants">
@foreach (var tenant in Model.TenantSettings) {
<li class="tenant @tenant.State.CurrentState">
<div class="summary">
<div class="properties">
<h3>@tenant.Name
@if (!string.IsNullOrEmpty(tenant.RequestUrlHost)) {
<span class="tenantHost"> - @Html.Link(Url.Tenant(tenant), Url.Tenant(tenant))</span>
}</h3>
</div>
<div class="related">
@if (!string.Equals(tenant.Name, "default", StringComparison.OrdinalIgnoreCase)) { //todo: (heskew) base this off the view model so logic on what can be removed and have its state changed stays in the controller
var t = tenant;
@Html.DisplayFor(m => t, string.Format("ActionsFor{0}", tenant.State.CurrentState), "") @T(" | ")
}
@Html.ActionLink(T("Edit").ToString(), "Edit", new {name = tenant.Name, area = "Orchard.MultiTenancy"})
</div>
</div>
</li>
}
</ul>

View File

@ -62,6 +62,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Tags", "Orchard.Web
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyMce", "Orchard.Web\Modules\TinyMce\TinyMce.csproj", "{954CA994-D204-468B-9D69-51F6AD3E1C29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.MultiTenancy", "Orchard.Web\Modules\Orchard.MultiTenancy\Orchard.MultiTenancy.csproj", "{72457126-E118-4171-A08F-9A709EE4B7FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Media", "Orchard.Web\Modules\Orchard.Media\Orchard.Media.csproj", "{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Email", "Orchard.Web\Modules\Orchard.Email\Orchard.Email.csproj", "{05660F47-D649-48BD-9DED-DF4E01E7CFF9}"
@ -315,6 +317,16 @@ Global
{954CA994-D204-468B-9D69-51F6AD3E1C29}.FxCop|Any CPU.Build.0 = Release|Any CPU
{954CA994-D204-468B-9D69-51F6AD3E1C29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{954CA994-D204-468B-9D69-51F6AD3E1C29}.Release|Any CPU.Build.0 = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.CodeCoverage|Any CPU.ActiveCfg = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.CodeCoverage|Any CPU.Build.0 = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.Coverage|Any CPU.Build.0 = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.FxCop|Any CPU.ActiveCfg = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.FxCop|Any CPU.Build.0 = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72457126-E118-4171-A08F-9A709EE4B7FC}.Release|Any CPU.Build.0 = Release|Any CPU
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}.CodeCoverage|Any CPU.ActiveCfg = Release|Any CPU
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}.CodeCoverage|Any CPU.Build.0 = Release|Any CPU
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
@ -350,6 +362,7 @@ Global
{0E7646E8-FE8F-43C1-8799-D97860925EC4} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{5D0F00F0-26C9-4785-AD61-B85710C60EB0} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{954CA994-D204-468B-9D69-51F6AD3E1C29} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{72457126-E118-4171-A08F-9A709EE4B7FC} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{05660F47-D649-48BD-9DED-DF4E01E7CFF9} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{ABC826D4-2FA1-4F2F-87DE-E6095F653810} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA}

View File

@ -3,18 +3,20 @@ using System.Web;
using System.Web.Security;
using Orchard.Logging;
using Orchard.ContentManagement;
using Orchard.Mvc;
using Orchard.Services;
namespace Orchard.Security.Providers {
public class FormsAuthenticationService : IAuthenticationService {
private readonly IClock _clock;
private readonly IContentManager _contentManager;
private readonly HttpContextBase _httpContext;
private readonly IHttpContextAccessor _httpContextAccessor;
public FormsAuthenticationService(IClock clock, IContentManager contentManager, HttpContextBase httpContext) {
public FormsAuthenticationService(IClock clock, IContentManager contentManager, IHttpContextAccessor httpContextAccessor) {
_clock = clock;
_contentManager = contentManager;
_httpContext = httpContext;
_httpContextAccessor = httpContextAccessor;
Logger = NullLogger.Instance;
// TEMP: who can say...
@ -47,8 +49,9 @@ namespace Orchard.Security.Providers {
if (FormsAuthentication.CookieDomain != null) {
cookie.Domain = FormsAuthentication.CookieDomain;
}
_httpContext.Response.Cookies.Add(cookie);
var httpContext = _httpContextAccessor.Current();
httpContext.Response.Cookies.Add(cookie);
}
public void SignOut() {
@ -56,11 +59,12 @@ namespace Orchard.Security.Providers {
}
public IUser GetAuthenticatedUser() {
if (!_httpContext.Request.IsAuthenticated || !(_httpContext.User.Identity is FormsIdentity)) {
var httpContext = _httpContextAccessor.Current();
if (!httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity)) {
return null;
}
var formsIdentity = (FormsIdentity)_httpContext.User.Identity;
var formsIdentity = (FormsIdentity)httpContext.User.Identity;
var userData = formsIdentity.Ticket.UserData;
int userId;
if (!int.TryParse(userData, out userId)) {