mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-20 10:47:56 +08:00
Specific Driver for SmtpSettingPart in order to encrypt/decrypt the password
--HG-- branch : dev
This commit is contained in:
@@ -170,6 +170,14 @@
|
|||||||
XPath="/configuration/system.web/compilation/@debug"
|
XPath="/configuration/system.web/compilation/@debug"
|
||||||
Value="false" />
|
Value="false" />
|
||||||
|
|
||||||
|
<XmlUpdate XmlFileName="$(StageFolder)\web.config"
|
||||||
|
XPath="/configuration/system.web/machineKey/@validationKey"
|
||||||
|
Value="AutoGenerate" />
|
||||||
|
|
||||||
|
<XmlUpdate XmlFileName="$(StageFolder)\web.config"
|
||||||
|
XPath="/configuration/system.web/machineKey/@decryptionKey"
|
||||||
|
Value="AutoGenerate" />
|
||||||
|
|
||||||
<XmlUpdate XmlFileName="$(StageFolder)\Config\Diagnostics.config"
|
<XmlUpdate XmlFileName="$(StageFolder)\Config\Diagnostics.config"
|
||||||
XPath="/system.diagnostics/trace/@autoflush"
|
XPath="/system.diagnostics/trace/@autoflush"
|
||||||
Value="false" />
|
Value="false" />
|
||||||
|
@@ -0,0 +1,29 @@
|
|||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Email.Models;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Email.Drivers {
|
||||||
|
|
||||||
|
// We define a specific driver instead of using a TemplateFilterForRecord, because we need the ;odel to be the part and not the record.
|
||||||
|
// Thus the encryption/decryption will be done when accessing the part's property
|
||||||
|
|
||||||
|
public class SmtpSettingsPartDriver : ContentPartDriver<SmtpSettingsPart> {
|
||||||
|
public SmtpSettingsPartDriver() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
protected override string Prefix { get { return "SmtpSettings"; } }
|
||||||
|
|
||||||
|
protected override DriverResult Editor(SmtpSettingsPart termPart) {
|
||||||
|
return ContentPartTemplate(termPart, "Parts/Smtp.SiteSettings");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(SmtpSettingsPart termPart, IUpdateModel updater) {
|
||||||
|
updater.TryUpdateModel(termPart, Prefix, null, null);
|
||||||
|
return Editor(termPart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -9,7 +9,6 @@ namespace Orchard.Email.Handlers {
|
|||||||
public SmtpSettingsPartHandler(IRepository<SmtpSettingsPartRecord> repository) {
|
public SmtpSettingsPartHandler(IRepository<SmtpSettingsPartRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<SmtpSettingsPart>("Site"));
|
Filters.Add(new ActivatingFilter<SmtpSettingsPart>("Site"));
|
||||||
Filters.Add(StorageFilter.For(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
Filters.Add(new TemplateFilterForRecord<SmtpSettingsPartRecord>("SmtpSettings", "Parts/Smtp.SiteSettings"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
using Orchard.ContentManagement;
|
using System.Text;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Orchard.Email.Models {
|
namespace Orchard.Email.Models {
|
||||||
@@ -40,8 +42,8 @@ namespace Orchard.Email.Models {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Password {
|
public string Password {
|
||||||
get { return Record.Password; }
|
get { return String.IsNullOrWhiteSpace(Record.Password) ? String.Empty : Encoding.UTF8.GetString(MachineKey.Decode(Record.Password, MachineKeyProtection.All)); ; }
|
||||||
set { Record.Password = value; }
|
set { Record.Password = String.IsNullOrWhiteSpace(value) ? String.Empty : MachineKey.Encode(Encoding.UTF8.GetBytes(value), MachineKeyProtection.All); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -66,6 +66,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DataMigrations\EmailDataMigration.cs" />
|
<Compile Include="DataMigrations\EmailDataMigration.cs" />
|
||||||
|
<Compile Include="Drivers\SmtpSettingsPartDriver.cs" />
|
||||||
<Compile Include="Handlers\SmtpSettingsPartHandler.cs" />
|
<Compile Include="Handlers\SmtpSettingsPartHandler.cs" />
|
||||||
<Compile Include="Models\SmtpSettingsPart.cs" />
|
<Compile Include="Models\SmtpSettingsPart.cs" />
|
||||||
<Compile Include="Models\SmtpSettingsPartRecord.cs" />
|
<Compile Include="Models\SmtpSettingsPartRecord.cs" />
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SmtpSettingsPartRecord>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SmtpSettingsPart>" %>
|
||||||
<%@ Import Namespace="Orchard.Email.Models"%>
|
<%@ Import Namespace="Orchard.Email.Models"%>
|
||||||
<%@ Import Namespace="System.Net.Mail" %>
|
<%@ Import Namespace="System.Net.Mail" %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
Reference in New Issue
Block a user