全球化与本地化

This commit is contained in:
administrator committed 2024-04-12 23:34:29 +08:00
1 parent 6fef1a9ea0
commit 77b9f64039
15 files changed
+649 -7

No files matched your search

@@ -3,19 +3,20 @@ using HelloShop.IdentityService.Entities;
using HelloShop.IdentityService.EntityFrameworks;
using HelloShop.IdentityService.Models.Users;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace HelloShop.IdentityService.Validations.Users;
public class UserCreateRequestValidator : AbstractValidator<UserCreateRequest>
{
public UserCreateRequestValidator(IdentityServiceDbContext dbContext)
public UserCreateRequestValidator(IdentityServiceDbContext dbContext,IStringLocalizer<UserCreateRequest> localizer )
{
RuleFor(m => m.UserName).NotNull().NotEmpty().Length(8, 16).Matches("^[a-zA-Z]+$");
RuleFor(m => m.PhoneNumber).NotNull().NotEmpty().Length(11).Matches(@"^1\d{10}$").Must((phoneNumber) =>
{
return !dbContext.Set<User>().Any(e => e.PhoneNumber == phoneNumber);
});
}).WithMessage(localizer["PhoneNumberAlreadyExists"]);
RuleFor(m => m.Password).NotNull().NotEmpty().Length(8, 16);