SysContextToken.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using System.Collections.Generic;
  2. //using Liger.Common.Extensions;
  3. using System;
  4. namespace LigerRM.Common
  5. {
  6. public sealed class SysContextToken
  7. {
  8. public static void SetCurrent(int userid)
  9. {
  10. CurrentUserID = userid.ToString();
  11. }
  12. public static void ClearUserStatus()
  13. {
  14. SsoTokenHelper.SetToken("userid", "", DateTime.Now);
  15. }
  16. /// <summary>
  17. /// 当前用户角色 多个用逗号隔开
  18. /// </summary>
  19. public static string roleid
  20. {
  21. get
  22. {
  23. try
  24. {
  25. return SsoTokenHelper.GetTokenValue("roleid").ToString();
  26. }
  27. catch
  28. {
  29. return "0";
  30. }
  31. }
  32. set
  33. {
  34. var Token = SsoTokenHelper.GetToken("roleid");
  35. if (Token != null)
  36. {
  37. SsoTokenHelper.SetToken("roleid", value, DateTime.Now.AddHours(1));
  38. }
  39. else
  40. {
  41. //有效期,一个钟头
  42. SsoTokenHelper.AddToken("roleid", value, DateTime.Now.AddHours(1));
  43. }
  44. }
  45. }
  46. /// <summary>
  47. /// 当前用户部门
  48. /// </summary>
  49. public static string CurrentDeptID
  50. {
  51. get
  52. {
  53. try
  54. {
  55. return SsoTokenHelper.GetTokenValue("CurrentDeptID").ToString();
  56. }
  57. catch
  58. {
  59. return "0";
  60. }
  61. }
  62. set
  63. {
  64. var Token = SsoTokenHelper.GetToken("CurrentDeptID");
  65. if (Token != null)
  66. {
  67. SsoTokenHelper.SetToken("CurrentDeptID", value.ToString(), DateTime.Now.AddHours(1));
  68. }
  69. else
  70. {
  71. //有效期,一个钟头
  72. SsoTokenHelper.AddToken("CurrentDeptID", value.ToString(), DateTime.Now.AddHours(1));
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 供应商ID 如果当前用户是供应商,需要这个
  78. /// </summary>
  79. public static string CurrentSupplierID
  80. {
  81. get
  82. {
  83. try
  84. {
  85. return SsoTokenHelper.GetTokenValue("CurrentSupplierID").ToString();
  86. }
  87. catch
  88. {
  89. return "0";
  90. }
  91. }
  92. set
  93. {
  94. var Token = SsoTokenHelper.GetToken("CurrentSupplierID");
  95. if (Token != null)
  96. {
  97. SsoTokenHelper.SetToken("CurrentSupplierID", value.ToString(), DateTime.Now.AddHours(1));
  98. }
  99. else
  100. {
  101. //有效期,一个钟头
  102. SsoTokenHelper.AddToken("CurrentSupplierID", value.ToString(), DateTime.Now.AddHours(1));
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 用户ID
  108. /// </summary>
  109. public static string CurrentUserID
  110. {
  111. get
  112. {
  113. try
  114. {
  115. return SsoTokenHelper.GetTokenValue("userid").ToString();
  116. }
  117. catch
  118. {
  119. return "0";
  120. }
  121. }
  122. set
  123. {
  124. var Token = SsoTokenHelper.GetToken("userid");
  125. if (Token != null)
  126. {
  127. SsoTokenHelper.SetToken("userid", value.ToString(), DateTime.Now.AddHours(1));
  128. }
  129. else
  130. {
  131. //有效期,一个钟头
  132. SsoTokenHelper.AddToken("userid", value.ToString(), DateTime.Now.AddHours(1));
  133. }
  134. }
  135. }
  136. public static string CurrentEmployeeID
  137. {
  138. get
  139. {
  140. try
  141. {
  142. return SsoTokenHelper.GetTokenValue("CurrentEmployeeID").ToString();
  143. }
  144. catch
  145. {
  146. return "0";
  147. }
  148. }
  149. set
  150. {
  151. var Token = SsoTokenHelper.GetToken("CurrentEmployeeID");
  152. if (Token != null)
  153. {
  154. SsoTokenHelper.SetToken("CurrentEmployeeID", value.ToString(), DateTime.Now.AddHours(1));
  155. }
  156. else
  157. {
  158. //有效期,一个钟头
  159. SsoTokenHelper.AddToken("CurrentEmployeeID", value.ToString(), DateTime.Now.AddHours(1));
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 上次登录时间
  165. /// </summary>
  166. public static string CurrentUserLastLoginTime
  167. {
  168. get
  169. {
  170. return SsoTokenHelper.GetTokenValue("CurrentUserLastLoginTime");
  171. }
  172. set
  173. {
  174. var Token = SsoTokenHelper.GetToken("CurrentUserLastLoginTime");
  175. if (Token != null)
  176. {
  177. SsoTokenHelper.SetToken("CurrentUserLastLoginTime", value.ToString(), DateTime.Now.AddHours(1));
  178. }
  179. else
  180. {
  181. //有效期,一个钟头
  182. SsoTokenHelper.AddToken("CurrentUserLastLoginTime", value.ToString(), DateTime.Now.AddHours(1));
  183. }
  184. }
  185. }
  186. public static string CurrentUserTitle
  187. {
  188. get
  189. {
  190. try
  191. {
  192. return SsoTokenHelper.GetTokenValue("username").ToString();
  193. }
  194. catch
  195. {
  196. return "0";
  197. }
  198. }
  199. set
  200. {
  201. var Token = SsoTokenHelper.GetToken("username");
  202. if (Token != null)
  203. {
  204. SsoTokenHelper.SetToken("username", value, DateTime.Now.AddHours(1));
  205. }
  206. else
  207. {
  208. //有效期,一个钟头
  209. SsoTokenHelper.AddToken("username", value, DateTime.Now.AddHours(1));
  210. }
  211. }
  212. }
  213. }
  214. }