mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 12:53:33 +08:00
Added some data annotations to validate SetupViewModel
--HG-- branch : dev
This commit is contained in:
@@ -111,6 +111,8 @@
|
|||||||
<Compile Include="Scheduling\Models\Task.cs" />
|
<Compile Include="Scheduling\Models\Task.cs" />
|
||||||
<Compile Include="Settings\Controllers\SiteSettingsDriver.cs" />
|
<Compile Include="Settings\Controllers\SiteSettingsDriver.cs" />
|
||||||
<Compile Include="Settings\Permissions.cs" />
|
<Compile Include="Settings\Permissions.cs" />
|
||||||
|
<Compile Include="Setup\Annotations\SqlDatabaseConnectionStringAttribute.cs" />
|
||||||
|
<Compile Include="Setup\Annotations\StringLengthMin.cs" />
|
||||||
<Compile Include="Setup\Controllers\SetupController.cs" />
|
<Compile Include="Setup\Controllers\SetupController.cs" />
|
||||||
<Compile Include="Setup\Routes.cs" />
|
<Compile Include="Setup\Routes.cs" />
|
||||||
<Compile Include="Setup\Services\ISetupService.cs" />
|
<Compile Include="Setup\Services\ISetupService.cs" />
|
||||||
|
@@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Setup.Annotations {
|
||||||
|
public class SqlDatabaseConnectionStringAttribute : ValidationAttribute {
|
||||||
|
public override bool IsValid(object value) {
|
||||||
|
if (value is string && ((string)value).Length > 0) {
|
||||||
|
try {
|
||||||
|
var connectionStringBuilder = new SqlConnectionStringBuilder(value as string);
|
||||||
|
|
||||||
|
//TODO: (erikpo) Should the keys be checked here to ensure that a valid combination was entered? Needs investigation.
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
src/Orchard.Web/Core/Setup/Annotations/StringLengthMin.cs
Normal file
19
src/Orchard.Web/Core/Setup/Annotations/StringLengthMin.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Setup.Annotations {
|
||||||
|
public class StringLengthMin : ValidationAttribute {
|
||||||
|
private readonly int _minimumLength;
|
||||||
|
|
||||||
|
public StringLengthMin(int minimumLength) {
|
||||||
|
_minimumLength = minimumLength;
|
||||||
|
|
||||||
|
if (minimumLength <= 1)
|
||||||
|
throw new ArgumentException("Value must be greater than or equal to 2", "minimumLength");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsValid(object value) {
|
||||||
|
return !(value is string) || (value as string).Length >= _minimumLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,10 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Orchard.Core.Setup.Annotations;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Core.Setup.ViewModels {
|
namespace Orchard.Core.Setup.ViewModels {
|
||||||
public class SetupViewModel : BaseViewModel {
|
public class SetupViewModel : BaseViewModel {
|
||||||
|
[Required, StringLength(70)]
|
||||||
public string SiteName { get; set; }
|
public string SiteName { get; set; }
|
||||||
|
[StringLengthMin(3), StringLength(25)]
|
||||||
public string AdminUsername { get; set; }
|
public string AdminUsername { get; set; }
|
||||||
|
[StringLengthMin(6), StringLength(20)]
|
||||||
public string AdminPassword { get; set; }
|
public string AdminPassword { get; set; }
|
||||||
|
[SqlDatabaseConnectionString]
|
||||||
public string DatabaseConnectionString { get; set; }
|
public string DatabaseConnectionString { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user