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()