feat: 个人中心完成保存显示名称与更改密码功能
This commit is contained in:
parent
8b280cef15
commit
7c2935bb1b
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public class User
|
|||
/// 获得/设置 用户默认登陆 App 标识
|
||||
/// </summary>
|
||||
[Display(Name = "默认 APP")]
|
||||
[NotNull]
|
||||
public string? App { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -136,6 +136,30 @@ class UserService : IUser
|
|||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新密码方法
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <param name="newPassword"></param>
|
||||
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<User>(sql, password, passSalt, userName) == 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool SaveDisplayName(string userName, string displayName) => Database.Update<User>("set DisplayName = @1 where UserName = @0", userName, displayName) == 1;
|
||||
|
||||
/// <summary>
|
||||
/// 创建手机用户
|
||||
/// </summary>
|
||||
|
|
|
@ -65,6 +65,22 @@ public interface IUser
|
|||
/// <returns></returns>
|
||||
bool SaveUsersByRoleId(string? roleId, IEnumerable<string> userIds);
|
||||
|
||||
/// <summary>
|
||||
/// 更新密码方法
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <param name="newPassword"></param>
|
||||
bool ChangePassword(string userName, string password, string newPassword);
|
||||
|
||||
/// <summary>
|
||||
/// 保存显示名称方法
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="displayName"></param>
|
||||
/// <returns></returns>
|
||||
bool SaveDisplayName(string userName, string displayName);
|
||||
|
||||
/// <summary>
|
||||
/// 获得所有用户
|
||||
/// </summary>
|
||||
|
|
|
@ -37,6 +37,10 @@ public partial class Profiles
|
|||
[NotNull]
|
||||
private IUser? UserService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private ToastService? ToastService { get; set; }
|
||||
|
||||
private List<UploadFile> PreviewFileList { get; } = new(new[] { new UploadFile { PrevUrl = "/images/Argo.png" } });
|
||||
|
||||
/// <summary>
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue