LoginPages.razor.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using Microsoft.AspNetCore.Components.Authorization;
  4. using System.Net.Http;
  5. using System.Net.Http.Json;
  6. using wispro.sp.share.webViewObject;
  7. using wispro.sp.web.Services;
  8. using System.IdentityModel.Tokens.Jwt;
  9. using Microsoft.IdentityModel.Tokens;
  10. using System.Linq;
  11. using System.Security.Claims;
  12. using Blazored.LocalStorage;
  13. using System;
  14. using System.Text.Json;
  15. using wispro.sp.entity;
  16. using wispro.sp.share;
  17. using Microsoft.AspNetCore.Components.Web;
  18. namespace wispro.sp.web.Pages
  19. {
  20. public partial class LoginPages
  21. {
  22. [Inject] public HttpClient Http { get; set; }
  23. [Inject] public MessageService MsgSvr { get; set; }
  24. //[Inject] public AuthenticationStateProvider AuthProvider { get; set; }
  25. [Inject] public IUserService _UserService { get; set; }
  26. [Inject] public IAuthService authService { get; set; }
  27. [Inject] public NavigationManager navigation { get; set; }
  28. loginDto model = new loginDto();
  29. bool isLoading;
  30. async void OnLogin()
  31. {
  32. isLoading = true;
  33. bool result = await authService.LoginAsync(model);
  34. if (result)
  35. {
  36. if (model.Password == "12345678")
  37. {
  38. navigation.NavigateTo("/ChangePassword/true");
  39. }
  40. else
  41. {
  42. navigation.NavigateTo("/Home");
  43. }
  44. }
  45. else
  46. {
  47. _ = MsgSvr.Error($"用户名或密码错误");
  48. }
  49. isLoading = false;
  50. }
  51. bool ShowResetPassword = false;
  52. private Staff EditingStaff = new Staff();
  53. void ResetPassword()
  54. {
  55. ShowResetPassword = true;
  56. EditingStaff = new Staff();
  57. }
  58. private async System.Threading.Tasks.Task HandleOk(MouseEventArgs e)
  59. {
  60. if(String.IsNullOrEmpty(EditingStaff.Account ) || string.IsNullOrEmpty(EditingStaff.Mail)){
  61. await MsgSvr.Success("请输入账号名称和邮箱!");
  62. return;
  63. }
  64. var data = await authService.ResetPassword(EditingStaff.Account,EditingStaff.Mail);
  65. if (data.Success)
  66. {
  67. await MsgSvr.Success("重置成功,新密码已发您邮箱!");
  68. ShowResetPassword = false;
  69. }
  70. else
  71. {
  72. await MsgSvr.Error($"请求发生错误 {data.ErrorMessage}");
  73. }
  74. }
  75. private void HandleCancel(MouseEventArgs e)
  76. {
  77. ShowResetPassword = false;
  78. }
  79. }
  80. }