From 7c2935bb1b7da20bcd45c958c054e69e98bde21c Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 13 Jan 2022 13:37:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BF=9D=E5=AD=98=E6=98=BE=E7=A4=BA=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=B8=8E=E6=9B=B4=E6=94=B9=E5=AF=86=E7=A0=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/UserService.cs | 10 +++++ .../BootstrapAdmin.DataAccess.Models/User.cs | 1 + .../Services/UserService.cs | 24 +++++++++++ .../admin/BootstrapAdmin.Web.Core/IUser.cs | 16 +++++++ .../Pages/Admin/Profiles.razor.cs | 43 +++++++++++++------ 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/blazor/admin/BootStarpAdmin.DataAccess.FreeSql/Service/UserService.cs b/src/blazor/admin/BootStarpAdmin.DataAccess.FreeSql/Service/UserService.cs index 01d3128c..f81636d4 100644 --- a/src/blazor/admin/BootStarpAdmin.DataAccess.FreeSql/Service/UserService.cs +++ b/src/blazor/admin/BootStarpAdmin.DataAccess.FreeSql/Service/UserService.cs @@ -203,4 +203,14 @@ class UserService : IUser { throw new NotImplementedException(); } + + public bool ChangePassword(string userName, string password, string newPassword) + { + throw new NotImplementedException(); + } + + public bool SaveDisplayName(string userName, string displayName) + { + throw new NotImplementedException(); + } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs index f82d78d0..65c15257 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs @@ -42,6 +42,7 @@ public class User /// 获得/设置 用户默认登陆 App 标识 /// [Display(Name = "默认 APP")] + [NotNull] public string? App { get; set; } /// diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs index 51976d34..0b216358 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs @@ -136,6 +136,30 @@ class UserService : IUser return ret; } + /// + /// 更新密码方法 + /// + /// + /// + /// + public bool ChangePassword(string userName, string password, string newPassword) + { + var ret = false; + if (Authenticate(userName, password)) + { + var passSalt = LgbCryptography.GenerateSalt(); + password = LgbCryptography.ComputeHash(newPassword, passSalt); + string sql = "set Password = @0, PassSalt = @1 where UserName = @2"; + ret = Database.Update(sql, password, passSalt, userName) == 1; + } + return ret; + } + + /// + /// + /// + public bool SaveDisplayName(string userName, string displayName) => Database.Update("set DisplayName = @1 where UserName = @0", userName, displayName) == 1; + /// /// 创建手机用户 /// diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IUser.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IUser.cs index 068a439e..d58dc644 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IUser.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IUser.cs @@ -65,6 +65,22 @@ public interface IUser /// bool SaveUsersByRoleId(string? roleId, IEnumerable userIds); + /// + /// 更新密码方法 + /// + /// + /// + /// + bool ChangePassword(string userName, string password, string newPassword); + + /// + /// 保存显示名称方法 + /// + /// + /// + /// + bool SaveDisplayName(string userName, string displayName); + /// /// 获得所有用户 /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs index c65fd6bc..3cc392a7 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs @@ -37,6 +37,10 @@ public partial class Profiles [NotNull] private IUser? UserService { get; set; } + [Inject] + [NotNull] + private ToastService? ToastService { get; set; } + private List PreviewFileList { get; } = new(new[] { new UploadFile { PrevUrl = "/images/Argo.png" } }); /// @@ -58,23 +62,34 @@ public partial class Profiles Themes = DictService.GetThemes().ToSelectedItemList(); } - private Task OnSaveDisplayName(EditContext context) + private async Task ShowToast(bool result, string title) { - return Task.CompletedTask; - } - - private Task OnSavePassword(EditContext context) - { - return Task.CompletedTask; - } - - private Task OnSaveApp() - { - if (CurrentUser.App != null) + if (result) { - UserService.SaveApp(AppContext.UserName, CurrentUser.App); + await ToastService.Success(title, $"保存{title}成功"); } - return Task.CompletedTask; + else + { + await ToastService.Error(title, $"保存{title}失败"); + } + } + + private async Task OnSaveDisplayName(EditContext context) + { + var ret = UserService.SaveDisplayName(CurrentUser.DisplayName, CurrentUser.UserName); + await ShowToast(ret, "显示名称"); + } + + private async Task OnSavePassword(EditContext context) + { + var ret = UserService.ChangePassword(CurrentUser.UserName, CurrentUser.Password, CurrentUser.NewPassword); + await ShowToast(ret, "密码"); + } + + private async Task OnSaveApp() + { + var ret = UserService.SaveApp(AppContext.UserName, CurrentUser.App); + await ShowToast(ret, "默认应用"); } private Task OnSaveTheme()