ProvinceSessionContext.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.Configurations;
  3. using Hotline.Settings;
  4. using Microsoft.Extensions.Options;
  5. using Newtonsoft.Json;
  6. using XF.Domain.Authentications;
  7. namespace Hotline.Authentications
  8. {
  9. public class ProvinceSessionContext : ISessionContext
  10. {
  11. public const string Key = "ProvinceSessionContext";
  12. public ProvinceSessionContext(ISystemSettingCacheManager systemSettingCacheManager)
  13. {
  14. var setting = systemSettingCacheManager.GetSetting(SettingConstants.CityBaseConfiguration)?.SettingValue[0];
  15. var cityBase = JsonConvert.DeserializeObject<CityBaseConfiguration>(setting);
  16. var config = cityBase.CityProvince;
  17. UserId = config.UserId;
  18. UserName = config.UserName;
  19. OrgId = config.OrgId;
  20. OrgName = config.OrgName;
  21. OrgLevel = 1;
  22. }
  23. //取消写入
  24. /// <summary>
  25. /// Id of current tenant or null for host
  26. /// </summary>
  27. public string? UserId { get; init; }
  28. /// <summary>
  29. /// Id of current user or throw Exception for guest
  30. /// </summary>
  31. /// <exception cref="AuthenticationException"></exception>
  32. public string RequiredUserId => UserId ?? throw new ArgumentNullException();
  33. //取消写入
  34. public string? UserName { get; init; }
  35. public string? Phone { get; init; }
  36. /// <summary>
  37. /// Roles
  38. /// </summary>
  39. public string[] Roles { get; init; }
  40. public string? OrgId { get; init; }
  41. public string RequiredOrgId => OrgId ?? throw new ArgumentNullException();
  42. public string? OrgName { get; init; }
  43. public int OrgLevel { get; init; }
  44. public string? OrgAreaCode { get; init; }
  45. public bool OrgIsCenter { get; init; }
  46. /// <summary>
  47. /// 部门行政区划名称
  48. /// </summary>
  49. public string? OrgAreaName { get; init; }
  50. public string? AreaId { get; init; }
  51. public string? ClientId { get; init; }
  52. /// <summary>
  53. /// 工号
  54. /// </summary>
  55. public string? StaffNo { get; init; }
  56. /// <summary>
  57. /// 第三方平台用户唯一标识
  58. /// 例如: 微信的OpenId
  59. /// </summary>
  60. public string? OpenId { get; init; }
  61. public void ChangeSession(string id)
  62. {
  63. throw new NotImplementedException();
  64. }
  65. public async Task ChangeSessionAsync(string userId, CancellationToken cancellation)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. }
  70. }