mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Comments.Annotations {
|
||||
public class RequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute {
|
||||
public RequiredAttribute() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
return T("You must provide a {0} in order to comment.", name).Text;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommentRequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute {
|
||||
public CommentRequiredAttribute() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
return T("You must provide a Comment.", name).Text;
|
||||
}
|
||||
}
|
||||
|
||||
public class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
|
||||
public RegularExpressionAttribute(string pattern) : base(pattern) {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
return T("The {0} is not valid.", name).Text;
|
||||
}
|
||||
}
|
||||
}
|
@@ -65,6 +65,7 @@
|
||||
<Compile Include="Drivers\CommentsContainerPartDriver.cs" />
|
||||
<Compile Include="Drivers\CommentSettingsPartDriver.cs" />
|
||||
<Compile Include="Drivers\CommentsPartDriver.cs" />
|
||||
<Compile Include="Annotations\CommentValidationAttributes.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Shapes.cs" />
|
||||
<Compile Include="Models\ClosedCommentsRecord.cs" />
|
||||
|
@@ -1,20 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Comments.Annotations;
|
||||
|
||||
namespace Orchard.Comments.ViewModels {
|
||||
public class CommentsCreateViewModel {
|
||||
[Required(ErrorMessage="You must provide a Name in order to comment")]
|
||||
[Annotations.Required]
|
||||
[StringLength(255)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[RegularExpression(@"^[\w-]+@([\w-]+\.)+[\w]{2,4}$", ErrorMessage = "The Email is not valid")]
|
||||
[Annotations.RegularExpression(@"^[\w-]+@([\w-]+\.)+[\w]{2,4}$")]
|
||||
[StringLength(255)]
|
||||
public string Email { get; set; }
|
||||
|
||||
[StringLength(245)]
|
||||
[RegularExpression(@"^(http(s)?://)?([\w-]+\.)+[\S]+$", ErrorMessage = "The Url is not valid")]
|
||||
[Annotations.RegularExpression(@"^(http(s)?://)?([\w-]+\.)+[\S]+$")]
|
||||
public string SiteName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "You must provide a Comment")]
|
||||
[CommentRequired]
|
||||
public string CommentText { get; set; }
|
||||
|
||||
public int CommentedOn { get; set; }
|
||||
|
@@ -0,0 +1,88 @@
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Setup.Annotations {
|
||||
public class SiteNameValidAttribute : System.ComponentModel.DataAnnotations.RangeAttribute {
|
||||
private string _value;
|
||||
|
||||
public SiteNameValidAttribute(int maximumLength)
|
||||
: base(1, maximumLength) {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
_value = (value as string) ?? "";
|
||||
return base.IsValid(_value.Trim().Length);
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
if (string.IsNullOrWhiteSpace(_value))
|
||||
return T("Site name is required.").Text;
|
||||
|
||||
return T("Site name can be no longer than {0} characters.", Maximum).Text;
|
||||
}
|
||||
}
|
||||
|
||||
public class UserNameValidAttribute : System.ComponentModel.DataAnnotations.RangeAttribute {
|
||||
private string _value;
|
||||
|
||||
public UserNameValidAttribute(int minimumLength, int maximumLength)
|
||||
: base(minimumLength, maximumLength) {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
_value = (value as string) ?? "";
|
||||
return base.IsValid(_value.Trim().Length);
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
if (string.IsNullOrEmpty(_value))
|
||||
return T("User name is required.").Text;
|
||||
|
||||
return _value.Length < (int)Minimum
|
||||
? T("User name must be longer than {0} characters.", Minimum).Text
|
||||
: T("User name can be no longer than {0} characters.", Maximum).Text;
|
||||
}
|
||||
}
|
||||
|
||||
public class PasswordValidAttribute : System.ComponentModel.DataAnnotations.RangeAttribute {
|
||||
private string _value;
|
||||
|
||||
public PasswordValidAttribute(int minimumLength, int maximumLength)
|
||||
: base(minimumLength, maximumLength) {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
_value = (value as string) ?? "";
|
||||
return base.IsValid(_value.Trim().Length);
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
if (string.IsNullOrEmpty(_value))
|
||||
return T("Password is required.").Text;
|
||||
|
||||
return _value.Length < (int)Minimum
|
||||
? T("Password must be longer than {0} characters.", Minimum).Text
|
||||
: T("Password can be no longer than {0} characters.", Maximum).Text;
|
||||
}
|
||||
}
|
||||
|
||||
public class PasswordConfirmationRequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute {
|
||||
public PasswordConfirmationRequiredAttribute() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override string FormatErrorMessage(string name) {
|
||||
return T("Password confirmation is required.").Text;
|
||||
}
|
||||
}
|
||||
}
|
@@ -61,6 +61,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Annotations\SetupValidationAttributes.cs" />
|
||||
<Compile Include="Annotations\SqlDatabaseConnectionStringAttribute.cs" />
|
||||
<Compile Include="Annotations\StringLengthMin.cs" />
|
||||
<Compile Include="Commands\SetupCommand.cs" />
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Setup.Annotations;
|
||||
|
||||
namespace Orchard.Setup.ViewModels {
|
||||
@@ -7,13 +6,13 @@ namespace Orchard.Setup.ViewModels {
|
||||
DatabaseOptions = true;
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Site name is required."), StringLength(70, ErrorMessage = "Site name can be no longer than 70 characters.")]
|
||||
[SiteNameValid(maximumLength: 70)]
|
||||
public string SiteName { get; set; }
|
||||
[Required(ErrorMessage = "User name is required."), StringLengthMin(3, ErrorMessage = "User name must be longer than 3 characters."), StringLength(25, ErrorMessage = "User name can be no longer than 25 characters.")]
|
||||
[UserNameValid(minimumLength: 3, maximumLength: 25)]
|
||||
public string AdminUsername { get; set; }
|
||||
[Required(ErrorMessage = "Password is required."), StringLengthMin(6, ErrorMessage = "Password must be longer than 6 characters."), StringLength(50, ErrorMessage = "Password can be no longer than 50 characters.")]
|
||||
[PasswordValid(minimumLength: 6, maximumLength: 50)]
|
||||
public string AdminPassword { get; set; }
|
||||
[Required(ErrorMessage = "Password confirmation is required.")]
|
||||
[PasswordConfirmationRequired]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public bool DatabaseOptions { get; set; }
|
||||
[SqlDatabaseConnectionString]
|
||||
|
Reference in New Issue
Block a user