-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React to localization workaround removal for data annotations attribu…
…tes (#12333)
- Loading branch information
Showing
9 changed files
with
108 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/OrchardCore.Modules/OrchardCore.OpenId/UrlAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace OrchardCore.OpenId; | ||
|
||
public class UrlAttribute : ValidationAttribute | ||
{ | ||
private static readonly char[] _urlSeparators = new[] { ' ', ',' }; | ||
|
||
protected override ValidationResult IsValid(object value, ValidationContext validationContext) | ||
{ | ||
if (value != null) | ||
{ | ||
var urls = value.ToString(); | ||
|
||
foreach (var url in urls.Split(_urlSeparators, StringSplitOptions.RemoveEmptyEntries)) | ||
{ | ||
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || !uri.IsWellFormedOriginalString()) | ||
{ | ||
return new ValidationResult(ErrorMessage, new[] { urls }); | ||
} | ||
} | ||
} | ||
|
||
return ValidationResult.Success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 3 additions & 19 deletions
22
src/OrchardCore.Modules/OrchardCore.Users/ViewModels/ChangeEmailViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,11 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.Email; | ||
|
||
namespace OrchardCore.Users.ViewModels | ||
{ | ||
public class ChangeEmailViewModel : IValidatableObject | ||
public class ChangeEmailViewModel | ||
{ | ||
[Required(ErrorMessage = "Email is required.")] | ||
[Email.EmailAddress(ErrorMessage = "Invalid Email.")] | ||
public string Email { get; set; } | ||
|
||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
var emailAddressValidator = validationContext.GetService<IEmailAddressValidator>(); | ||
var S = validationContext.GetService<IStringLocalizer<ChangeEmailViewModel>>(); | ||
if (string.IsNullOrWhiteSpace(Email)) | ||
{ | ||
yield return new ValidationResult(S["Email is required."], new[] { nameof(Email) }); | ||
} | ||
else if (!emailAddressValidator.Validate(Email)) | ||
{ | ||
yield return new ValidationResult(S["Invalid Email."], new[] { nameof(Email) }); | ||
} | ||
} | ||
} | ||
} |
18 changes: 2 additions & 16 deletions
18
src/OrchardCore.Modules/OrchardCore.Users/ViewModels/EditUserInformationViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.Email; | ||
|
||
namespace OrchardCore.Users.ViewModels | ||
{ | ||
public class EditUserInformationViewModel : IValidatableObject | ||
public class EditUserInformationViewModel | ||
{ | ||
[Required] | ||
public string UserName { get; set; } | ||
|
||
[Required] | ||
[Email.EmailAddress(ErrorMessage = "Invalid Email.")] | ||
public string Email { get; set; } | ||
|
||
[BindNever] | ||
public bool IsEditingDisabled { get; set; } | ||
|
||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
var emailAddressValidator = validationContext.GetService<IEmailAddressValidator>(); | ||
var S = validationContext.GetService<IStringLocalizer<EditUserInformationViewModel>>(); | ||
|
||
if (!string.IsNullOrEmpty(Email) && !emailAddressValidator.Validate(Email)) | ||
{ | ||
yield return new ValidationResult(S["Invalid Email."], new[] { "Email" }); | ||
} | ||
} | ||
} | ||
} |
24 changes: 3 additions & 21 deletions
24
src/OrchardCore.Modules/OrchardCore.Users/ViewModels/ForgotPasswordViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,11 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.Email; | ||
|
||
namespace OrchardCore.Users.ViewModels | ||
{ | ||
public class ForgotPasswordViewModel : IValidatableObject | ||
public class ForgotPasswordViewModel | ||
{ | ||
[Required] | ||
[Required(ErrorMessage = "Email is required.")] | ||
[Email.EmailAddress(ErrorMessage = "Invalid Email.")] | ||
public string Email { get; set; } | ||
|
||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
var emailAddressValidator = validationContext.GetService<IEmailAddressValidator>(); | ||
var S = validationContext.GetService<IStringLocalizer<ForgotPasswordViewModel>>(); | ||
|
||
if (string.IsNullOrWhiteSpace(Email)) | ||
{ | ||
yield return new ValidationResult(S["Email is required."], new[] { nameof(Email) }); | ||
} | ||
else if (!emailAddressValidator.Validate(Email)) | ||
{ | ||
yield return new ValidationResult(S["Invalid Email."], new[] { nameof(Email) }); | ||
} | ||
} | ||
} | ||
} |
15 changes: 2 additions & 13 deletions
15
src/OrchardCore.Modules/OrchardCore.Users/ViewModels/LinkExternalLoginViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,11 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Localization; | ||
|
||
namespace OrchardCore.Users.ViewModels | ||
{ | ||
public class LinkExternalLoginViewModel : IValidatableObject | ||
public class LinkExternalLoginViewModel | ||
{ | ||
[DataType(DataType.Password)] | ||
[Required(ErrorMessage = "Password is required.")] | ||
public string Password { get; set; } | ||
|
||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
var S = validationContext.GetService<IStringLocalizer<LinkExternalLoginViewModel>>(); | ||
if (string.IsNullOrWhiteSpace(Password)) | ||
{ | ||
yield return new ValidationResult(S["Password is required"], new[] { nameof(Password) }); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.