Specific Driver for SmtpSettingPart in order to encrypt/decrypt the password

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-09-02 15:32:47 -07:00
parent fcb27fdbae
commit a253985a40
6 changed files with 44 additions and 5 deletions

View File

@@ -170,6 +170,14 @@
XPath="/configuration/system.web/compilation/@debug"
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"
XPath="/system.diagnostics/trace/@autoflush"
Value="false" />

View File

@@ -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);
}
}
}

View File

@@ -9,7 +9,6 @@ namespace Orchard.Email.Handlers {
public SmtpSettingsPartHandler(IRepository<SmtpSettingsPartRecord> repository) {
Filters.Add(new ActivatingFilter<SmtpSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
Filters.Add(new TemplateFilterForRecord<SmtpSettingsPartRecord>("SmtpSettings", "Parts/Smtp.SiteSettings"));
}
}
}

View File

@@ -1,4 +1,6 @@
using Orchard.ContentManagement;
using System.Text;
using System.Web.Security;
using Orchard.ContentManagement;
using System;
namespace Orchard.Email.Models {
@@ -40,8 +42,8 @@ namespace Orchard.Email.Models {
}
public string Password {
get { return Record.Password; }
set { Record.Password = value; }
get { return String.IsNullOrWhiteSpace(Record.Password) ? String.Empty : Encoding.UTF8.GetString(MachineKey.Decode(Record.Password, MachineKeyProtection.All)); ; }
set { Record.Password = String.IsNullOrWhiteSpace(value) ? String.Empty : MachineKey.Encode(Encoding.UTF8.GetBytes(value), MachineKeyProtection.All); }
}
}
}

View File

@@ -66,6 +66,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataMigrations\EmailDataMigration.cs" />
<Compile Include="Drivers\SmtpSettingsPartDriver.cs" />
<Compile Include="Handlers\SmtpSettingsPartHandler.cs" />
<Compile Include="Models\SmtpSettingsPart.cs" />
<Compile Include="Models\SmtpSettingsPartRecord.cs" />

View File

@@ -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="System.Net.Mail" %>
<fieldset>