diff --git a/Atomx.Admin/Atomx.Admin.Client/Atomx.Admin.Client.csproj b/Atomx.Admin/Atomx.Admin.Client/Atomx.Admin.Client.csproj
index 44da03a..d442b1b 100644
--- a/Atomx.Admin/Atomx.Admin.Client/Atomx.Admin.Client.csproj
+++ b/Atomx.Admin/Atomx.Admin.Client/Atomx.Admin.Client.csproj
@@ -14,6 +14,7 @@
+
diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/DebugLocalization.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/DebugLocalization.razor
index 58f1813..49de35e 100644
--- a/Atomx.Admin/Atomx.Admin.Client/Pages/DebugLocalization.razor
+++ b/Atomx.Admin/Atomx.Admin.Client/Pages/DebugLocalization.razor
@@ -113,7 +113,7 @@
{
try
{
- jsResult = await JS.InvokeAsync("CookieReader.Read", "atomx.culture");
+ jsResult = await JS.InvokeAsync("cookies.Read", "atomx.culture");
}
catch (Exception ex)
{
diff --git a/Atomx.Admin/Atomx.Admin.Client/Program.cs b/Atomx.Admin/Atomx.Admin.Client/Program.cs
index 6ec603d..f83dfb8 100644
--- a/Atomx.Admin/Atomx.Admin.Client/Program.cs
+++ b/Atomx.Admin/Atomx.Admin.Client/Program.cs
@@ -6,6 +6,9 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Localization;
using System.Net.Http;
+using FluentValidation;
+using System.Linq;
+using System.Reflection;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
@@ -67,6 +70,8 @@ builder.Services.AddScoped(sp =>
return new HttpService(httpClient, httpContextAccessor);
});
+builder.Services.AddValidatorsFromAssembly(typeof(Atomx.Admin.Client.Validators.LoginModelValidator).Assembly);
+
builder.Services.AddAntDesign();
diff --git a/Atomx.Admin/Atomx.Admin.Client/Services/LocalizationProvider.cs b/Atomx.Admin/Atomx.Admin.Client/Services/LocalizationProvider.cs
index 19dec8f..f3938d8 100644
--- a/Atomx.Admin/Atomx.Admin.Client/Services/LocalizationProvider.cs
+++ b/Atomx.Admin/Atomx.Admin.Client/Services/LocalizationProvider.cs
@@ -169,7 +169,7 @@ namespace Atomx.Admin.Client.Services
{
if (_jsRuntime != null && OperatingSystem.IsBrowser())
{
- var cookieVal = await _jsRuntime.InvokeAsync("CookieReader.Read", CookieName);
+ var cookieVal = await _jsRuntime.InvokeAsync("cookies.Read", CookieName);
_logger?.LogDebug("Cookie '{CookieName}'='{CookieVal}'", CookieName, cookieVal);
if (!string.IsNullOrEmpty(cookieVal))
{
diff --git a/Atomx.Admin/Atomx.Admin.Client/Validators/LoginModelValidator.cs b/Atomx.Admin/Atomx.Admin.Client/Validators/LoginModelValidator.cs
index 2d91ac5..d3f4bd5 100644
--- a/Atomx.Admin/Atomx.Admin.Client/Validators/LoginModelValidator.cs
+++ b/Atomx.Admin/Atomx.Admin.Client/Validators/LoginModelValidator.cs
@@ -1,25 +1,36 @@
using Atomx.Admin.Client.Models;
using FluentValidation;
+using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators
{
public class LoginModelValidator : AbstractValidator
{
- public LoginModelValidator()
+ public LoginModelValidator(IStringLocalizer localizer)
{
- RuleFor(p => p.Account).NotEmpty().WithMessage("登录账号不能为空");
- RuleFor(p => p.Account).Length(2, 100).When(p => !string.IsNullOrEmpty(p.Account)).WithMessage("用户名长度必须再2-100个字符之间");
- //RuleFor(p => p.Account).EmailAddress().When(p => !p.Account.Contains("@") && !string.IsNullOrEmpty(p.Account)).WithMessage("电子邮件地址不正确");
+ // helper funcs to get localized text or fallback
+ string AccountEmpty() => localizer?["Login.Account.Empty"].Value ?? "登录账号不能为空";
+ string AccountLength() => localizer?["Login.Account.Length"].Value ?? "用户名长度必须再2-100个字符之间";
+ string PasswordEmpty() => localizer?["Login.Password.Empty"].Value ?? "请输入登录密码";
+ string PasswordLength() => localizer?["Login.Password.Length"].Value ?? "登录密码必须在6-32位长度之间";
- //RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
- //RuleFor(p => p.Username).Length(2, 50).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-50个字符之间");
- //RuleFor(p => p.Account).NotEmpty().WithMessage("电子邮件地址不能为空");
- //RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage(p => localizer["Form.Email.Invalid"]);
- //RuleFor(p => p.Email).MaximumLength(128).When(p => !string.IsNullOrEmpty(p.Email)).WithMessage(p => localizer["Form.Email.LengthInvalid"]);
- RuleFor(p => p.Password).NotEmpty().WithMessage("请输入登录密码");
- RuleFor(p => p.Password).Length(6, 32).When(p => !string.IsNullOrEmpty(p.Password)).WithMessage("登录密码必须在6-32位长度之间");
- //RuleFor(p => p.ConfirmPassword).NotEmpty().WithMessage(p => localizer["Form.ConfirmPassword.Empty"]);
- //RuleFor(p => p.ConfirmPassword).Equal(p => p.Password).When(p => !string.IsNullOrEmpty(p.Password) && !string.IsNullOrEmpty(p.ConfirmPassword)).WithMessage(p => localizer["Form.ConfirmPassword.Different"]);
+ RuleFor(p => p.Account)
+ .NotEmpty()
+ .WithMessage(_ => AccountEmpty());
+
+ RuleFor(p => p.Account)
+ .Length(2, 100)
+ .When(p => !string.IsNullOrEmpty(p.Account))
+ .WithMessage(_ => AccountLength());
+
+ RuleFor(p => p.Password)
+ .NotEmpty()
+ .WithMessage(_ => PasswordEmpty());
+
+ RuleFor(p => p.Password)
+ .Length(6, 32)
+ .When(p => !string.IsNullOrEmpty(p.Password))
+ .WithMessage(_ => PasswordLength());
}
public Func