You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
1.9 KiB

  1. using AbrBlazorTools;
  2. using Microsoft.AspNetCore.Components;
  3. using Models.Identity;
  4. using Newtonsoft.Json;
  5. namespace ApiUtils;
  6. public class UserUtils : IUserUtils
  7. {
  8. private readonly IHttpClientWithLoginToken _client;
  9. public UserUtils(IHttpClientWithLoginToken client)
  10. {
  11. _client = client;
  12. }
  13. public async Task<HttpResponseMessage> SendVerificationRequest(object otpModel)
  14. {
  15. return await _client.HttpPost("/api/AUTH/Login",otpModel);
  16. }
  17. public async Task<HttpResponseMessage> SendSignUpRequest(object accountModel)
  18. {
  19. return await _client.HttpPost("/api/AUTH/SignUp",accountModel);
  20. }
  21. public async Task<HttpResponseMessage> LoginWithPasswordRequest(object loginModel)
  22. {
  23. return await _client.HttpPost("/api/AUTH/LoginWithPassword",loginModel);
  24. }
  25. public async Task<HttpResponseMessage> CheckLogin(bool goToLogin = true)
  26. {
  27. return await _client.HttpGet("/api/AUTH/CheckLogin",true,goToLogin);
  28. }
  29. public async Task<HttpResponseMessage> RefreshToken(object refreshTokenModel)
  30. {
  31. return await _client.HttpPost("/api/Auth/refresh", refreshTokenModel);
  32. }
  33. public async Task<CheckLoginResponse> SaveEmailAndName(NameAndEmailModel model)
  34. {
  35. var res=await _client.HttpPost("/api/auth/SetNameAndEmail", model);
  36. if (!res.IsSuccessStatusCode)
  37. return null;
  38. return JsonConvert.DeserializeObject<CheckLoginResponse>(await res.Content.ReadAsStringAsync());
  39. }
  40. }
  41. public interface IUserUtils
  42. {
  43. Task<HttpResponseMessage> SendVerificationRequest(object otpModel);
  44. Task<HttpResponseMessage> LoginWithPasswordRequest(object loginModel);
  45. Task<HttpResponseMessage> SendSignUpRequest(object accountModel);
  46. Task<HttpResponseMessage> CheckLogin(bool goToLogin = true);
  47. Task<HttpResponseMessage> RefreshToken(object refreshTokenModel);
  48. Task<CheckLoginResponse> SaveEmailAndName(NameAndEmailModel model);
  49. }