mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-08-01 18:13:08 +08:00
Shifting settings. Settings are now saved into the infoset rather than a record. No migration, no record.
This commit is contained in:
parent
f7998bc95c
commit
5166c16c73
@ -6,10 +6,9 @@ using Orchard.SecureSocketsLayer.Models;
|
|||||||
|
|
||||||
namespace Orchard.SecureSocketsLayer.Handlers {
|
namespace Orchard.SecureSocketsLayer.Handlers {
|
||||||
public class SslSettingsPartHandler : ContentHandler {
|
public class SslSettingsPartHandler : ContentHandler {
|
||||||
public SslSettingsPartHandler(IRepository<SslSettingsPartRecord> repository) {
|
public SslSettingsPartHandler() {
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Filters.Add(new ActivatingFilter<SslSettingsPart>("Site"));
|
Filters.Add(new ActivatingFilter<SslSettingsPart>("Site"));
|
||||||
Filters.Add(StorageFilter.For(repository));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
using Orchard.Data.Migration;
|
|
||||||
|
|
||||||
namespace Orchard.SecureSocketsLayer {
|
|
||||||
public class Migrations : DataMigrationImpl {
|
|
||||||
public int Create() {
|
|
||||||
|
|
||||||
SchemaBuilder.CreateTable("SslSettingsPartRecord",
|
|
||||||
table => table
|
|
||||||
.ContentPartRecord()
|
|
||||||
.Column<bool>("CustomEnabled")
|
|
||||||
.Column<bool>("SecureEverything")
|
|
||||||
.Column<string>("Urls", c => c.Unlimited())
|
|
||||||
.Column<string>("SecureHostName")
|
|
||||||
.Column<string>("InsecureHostName")
|
|
||||||
);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +1,39 @@
|
|||||||
|
using System;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||||
|
|
||||||
namespace Orchard.SecureSocketsLayer.Models {
|
namespace Orchard.SecureSocketsLayer.Models {
|
||||||
public class SslSettingsPart : ContentPart<SslSettingsPartRecord> {
|
public class SslSettingsPart : ContentPart {
|
||||||
public string Urls
|
public string Urls
|
||||||
{
|
{
|
||||||
get { return Record.Urls; }
|
get { return this.As<InfosetPart>().Get<SslSettingsPart>("Urls"); }
|
||||||
set { Record.Urls = value; }
|
set { this.As<InfosetPart>().Set<SslSettingsPart>("Urls", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SecureEverything {
|
public bool SecureEverything {
|
||||||
get { return Record.SecureEverything; }
|
get {
|
||||||
set { Record.SecureEverything = value; }
|
var attributeValue = this.As<InfosetPart>().Get<SslSettingsPart>("SecureEverything");
|
||||||
|
return !String.IsNullOrWhiteSpace(attributeValue) && Convert.ToBoolean(attributeValue);
|
||||||
|
}
|
||||||
|
set { this.As<InfosetPart>().Set<SslSettingsPart>("SecureEverything", value.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CustomEnabled {
|
public bool CustomEnabled {
|
||||||
get { return Record.CustomEnabled; }
|
get {
|
||||||
set { Record.CustomEnabled = value; }
|
var attributeValue = this.As<InfosetPart>().Get<SslSettingsPart>("CustomEnabled");
|
||||||
|
return !String.IsNullOrWhiteSpace(attributeValue) && Convert.ToBoolean(attributeValue);
|
||||||
|
}
|
||||||
|
set { this.As<InfosetPart>().Set<SslSettingsPart>("CustomEnabled", value.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SecureHostName {
|
public string SecureHostName {
|
||||||
get { return Record.SecureHostName; }
|
get { return this.As<InfosetPart>().Get<SslSettingsPart>("SecureHostName"); }
|
||||||
set { Record.SecureHostName = value; }
|
set { this.As<InfosetPart>().Set<SslSettingsPart>("SecureHostName", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string InsecureHostName {
|
public string InsecureHostName {
|
||||||
get { return Record.InsecureHostName; }
|
get { return this.As<InfosetPart>().Get<SslSettingsPart>("InsecureHostName"); }
|
||||||
set { Record.InsecureHostName = value; }
|
set { this.As<InfosetPart>().Set<SslSettingsPart>("InsecureHostName", value); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +0,0 @@
|
|||||||
using Orchard.ContentManagement.Records;
|
|
||||||
|
|
||||||
namespace Orchard.SecureSocketsLayer.Models {
|
|
||||||
public class SslSettingsPartRecord : ContentPartRecord {
|
|
||||||
public virtual string Urls { get; set; }
|
|
||||||
public virtual bool SecureEverything { get; set; }
|
|
||||||
public virtual bool CustomEnabled { get; set; }
|
|
||||||
public virtual string SecureHostName { get; set; }
|
|
||||||
public virtual string InsecureHostName { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -82,11 +82,9 @@
|
|||||||
<Compile Include="Drivers\SslSettingsPartDriver.cs" />
|
<Compile Include="Drivers\SslSettingsPartDriver.cs" />
|
||||||
<Compile Include="Filters\SecureSocketsLayersFilter.cs" />
|
<Compile Include="Filters\SecureSocketsLayersFilter.cs" />
|
||||||
<Compile Include="Handlers\SslSettingsPartHandler.cs" />
|
<Compile Include="Handlers\SslSettingsPartHandler.cs" />
|
||||||
<Compile Include="Migrations.cs" />
|
|
||||||
<Compile Include="Models\SslSettingsPart.cs" />
|
<Compile Include="Models\SslSettingsPart.cs" />
|
||||||
<Compile Include="Models\SslSettingsPartRecord.cs" />
|
|
||||||
<Compile Include="Services\ISecureSocketsLayerService.cs" />
|
<Compile Include="Services\ISecureSocketsLayerService.cs" />
|
||||||
<Compile Include="Services\SecuredSocketsLayerService.cs" />
|
<Compile Include="Services\SecureSocketsLayerService.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\EditorTemplates\Parts\SecureSocketsLayer.Settings.cshtml" />
|
<Content Include="Views\EditorTemplates\Parts\SecureSocketsLayer.Settings.cshtml" />
|
||||||
|
@ -150,7 +150,7 @@ namespace Orchard.SecureSocketsLayer.Services {
|
|||||||
return requestContext;
|
return requestContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsRequestProtected(string path, string appPath, SslSettingsPartRecord settings) {
|
private static bool IsRequestProtected(string path, string appPath, SslSettingsPart settings) {
|
||||||
var match = false;
|
var match = false;
|
||||||
var sr = new StringReader(settings.Urls ?? "");
|
var sr = new StringReader(settings.Urls ?? "");
|
||||||
string pattern;
|
string pattern;
|
||||||
@ -183,17 +183,8 @@ namespace Orchard.SecureSocketsLayer.Services {
|
|||||||
: string.Equals(requestPath, pattern, StringComparison.OrdinalIgnoreCase);
|
: string.Equals(requestPath, pattern, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SslSettingsPartRecord GetSettings() {
|
private SslSettingsPart GetSettings() {
|
||||||
return _cacheManager.Get("SslSettings", ctx => {
|
return _cacheManager.Get("SslSettings", ctx => _workContextAccessor.GetContext().CurrentSite.As<SslSettingsPart>());
|
||||||
var settings = _workContextAccessor.GetContext().CurrentSite.As<SslSettingsPart>();
|
|
||||||
return new SslSettingsPartRecord {
|
|
||||||
CustomEnabled = settings.CustomEnabled,
|
|
||||||
Urls = settings.Urls,
|
|
||||||
SecureEverything = settings.SecureEverything,
|
|
||||||
InsecureHostName = settings.InsecureHostName,
|
|
||||||
SecureHostName = settings.SecureHostName
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string MakeInsecure(string path) {
|
private string MakeInsecure(string path) {
|
@ -67,10 +67,10 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
|||||||
partElement.Add(fieldElement);
|
partElement.Add(fieldElement);
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(valueName)) {
|
if (string.IsNullOrEmpty(valueName)) {
|
||||||
fieldElement.Value = value;
|
fieldElement.Value = value ?? "";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fieldElement.SetAttributeValue(XmlConvert.EncodeLocalName(valueName), value);
|
fieldElement.SetAttributeValue(XmlConvert.EncodeLocalName(valueName), value ?? "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user