BasePageModel.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. using Microsoft.Extensions.Caching.Memory;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace SupplierWeb
  11. {
  12. public class BasePageModel : PageModel
  13. {
  14. protected readonly IMemoryCache _cache;
  15. protected readonly IApiClient _client;
  16. public BasePageModel(IMemoryCache cache, IApiClient client)
  17. {
  18. _cache = cache;
  19. _client = client;
  20. }
  21. public string Message { get; set; }
  22. public string ErrorMessage { get; set; }
  23. public bool IsSuccess { get; set; } = true;
  24. }
  25. [Authorize]
  26. public abstract class LoginedPageModel : BasePageModel
  27. {
  28. public LoginedPageModel(IMemoryCache cache, IApiClient client) : base(cache, client)
  29. {
  30. }
  31. public string AppId
  32. {
  33. get
  34. {
  35. return User?.Claims?.SingleOrDefault(c => c.Type == "appid")?.Value;
  36. }
  37. }
  38. public string AppSecret
  39. {
  40. get
  41. {
  42. return User?.Claims?.SingleOrDefault(c => c.Type == "appSecret")?.Value;
  43. }
  44. }
  45. public string AccessToken
  46. {
  47. get
  48. {
  49. return User?.Claims?.SingleOrDefault(c => c.Type == "token")?.Value;
  50. }
  51. }
  52. public abstract int Index { get;}
  53. public abstract int SubIndex { get; }
  54. }
  55. }