diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 55c52e557..dd198ab39 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -111,6 +111,8 @@ + + diff --git a/src/Orchard.Web/Core/Setup/Annotations/SqlDatabaseConnectionStringAttribute.cs b/src/Orchard.Web/Core/Setup/Annotations/SqlDatabaseConnectionStringAttribute.cs new file mode 100644 index 000000000..82dff4e80 --- /dev/null +++ b/src/Orchard.Web/Core/Setup/Annotations/SqlDatabaseConnectionStringAttribute.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; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Setup/Annotations/StringLengthMin.cs b/src/Orchard.Web/Core/Setup/Annotations/StringLengthMin.cs new file mode 100644 index 000000000..d999d2a6c --- /dev/null +++ b/src/Orchard.Web/Core/Setup/Annotations/StringLengthMin.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Setup/ViewModels/SetupViewModel.cs b/src/Orchard.Web/Core/Setup/ViewModels/SetupViewModel.cs index 8f62660a8..268f03d20 100644 --- a/src/Orchard.Web/Core/Setup/ViewModels/SetupViewModel.cs +++ b/src/Orchard.Web/Core/Setup/ViewModels/SetupViewModel.cs @@ -1,10 +1,16 @@ +using System.ComponentModel.DataAnnotations; +using Orchard.Core.Setup.Annotations; using Orchard.Mvc.ViewModels; namespace Orchard.Core.Setup.ViewModels { public class SetupViewModel : BaseViewModel { + [Required, StringLength(70)] public string SiteName { get; set; } + [StringLengthMin(3), StringLength(25)] public string AdminUsername { get; set; } + [StringLengthMin(6), StringLength(20)] public string AdminPassword { get; set; } + [SqlDatabaseConnectionString] public string DatabaseConnectionString { get; set; } } } \ No newline at end of file