ChangePassword.razor.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Microsoft.AspNetCore.Components;
  2. using Microsoft.JSInterop;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using wispro.sp.share.webViewObject;
  8. using wispro.sp.web.Services;
  9. namespace wispro.sp.web.Pages
  10. {
  11. public partial class ChangePassword
  12. {
  13. private changePasswordDto dto = new changePasswordDto();
  14. private Models.CurrentUser user;
  15. private string ChecknewPassword;
  16. [Parameter]
  17. public bool FirstLogin { get; set; }
  18. [Inject]
  19. protected IUserService userService { get; set; }
  20. [Inject] public NavigationManager navigation { get; set; }
  21. [Inject] public IJSRuntime JSRuntime { get; set; }
  22. [Inject] public IAuthService authService { get; set; }
  23. protected async override Task OnInitializedAsync()
  24. {
  25. user =await userService.GetUser();
  26. dto = new changePasswordDto();
  27. dto.UserId = user.Userid.Value;
  28. //Console.WriteLine($"OnInitializedAsync:{System.Text.Json.JsonSerializer.Serialize(user)}");
  29. await base.OnInitializedAsync();
  30. }
  31. private string ErrorMsg;
  32. public async void OnSubmit()
  33. {
  34. //Console.WriteLine($"OnSubmit:{System.Text.Json.JsonSerializer.Serialize(user)}");
  35. //Console.WriteLine($"用户ID:{dto.UserId}");
  36. //Console.WriteLine($"用户名:{user.Name}-{user.Userid}");
  37. //Console.WriteLine($"旧密码:{dto.oldPassword}");
  38. //Console.WriteLine($"新密码:{dto.newPassword}");
  39. //Console.WriteLine($"Check新密码:{ChecknewPassword}");
  40. ErrorMsg = "";
  41. if(dto.newPassword == ChecknewPassword)
  42. {
  43. if (string.IsNullOrEmpty(dto.newPassword))
  44. {
  45. ErrorMsg = "密码不能为空!";
  46. return;
  47. }
  48. var result = await authService.ChangePassword(dto);
  49. if (result)
  50. {
  51. OnCancel();
  52. }
  53. else
  54. {
  55. ErrorMsg = "修改发生了一些错误,请重试!";
  56. }
  57. }
  58. else
  59. {
  60. ErrorMsg = "新密码两次输入不一致!";
  61. }
  62. StateHasChanged();
  63. }
  64. public async void OnCancel()
  65. {
  66. if (FirstLogin)
  67. {
  68. navigation.NavigateTo("/Home");
  69. }
  70. else
  71. {
  72. await JSRuntime.InvokeVoidAsync("history.back");
  73. }
  74. }
  75. }
  76. }