SessionCookieCore.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using WMS.Util;
  3. using WMS.Info;
  4. namespace WMS.BZServices
  5. {
  6. /// <summary>
  7. /// 获取登录用户信息
  8. /// </summary>
  9. public class BZSessionCookieCore
  10. {
  11. public static string GetSessionCookieValue(string Key)
  12. {
  13. try
  14. {
  15. //return WebUtil.GetSession(Key);
  16. //if (SysSetCore.GetSysSet().IsSession)
  17. //{
  18. // return WebUtil.GetSession(Key);
  19. //}
  20. //else
  21. //{
  22. // return WebUtil.GetCookie(Key);
  23. //}
  24. }
  25. catch
  26. {
  27. }
  28. return "";
  29. }
  30. public static void WriteSessionCookieValue(string Key, string Value)
  31. {
  32. try
  33. {
  34. //if (SysSetCore.GetSysSet().IsSession)
  35. //{
  36. // WebUtil.WriteSession(Key, Value);
  37. //}
  38. //else
  39. //{
  40. // WebUtil.WriteCookie(Key, Value, 60 * 5);
  41. //}
  42. }
  43. catch (Exception ex)
  44. {
  45. //throw ex;
  46. }
  47. }
  48. public static void CheckVerifyCode(string VerifyCode)
  49. {
  50. try
  51. {
  52. if (GetUserPwdErrorNum() >= 3)
  53. {
  54. if (string.IsNullOrWhiteSpace(VerifyCode))
  55. {
  56. throw BZSysExCore.ThrowFailException("验证码为空。");
  57. }
  58. if (VerifyCode.ToUpper() != GetSessionCookieValue(BZSessionCookieConst.LoginVerifyCodeKey).ToUpper())
  59. {
  60. throw BZSysExCore.ThrowFailException("验证码错误。");
  61. }
  62. }
  63. }
  64. catch (Exception ex)
  65. {
  66. throw ex;
  67. }
  68. }
  69. public static int GetUserPwdErrorNum()
  70. {
  71. int error = 0;
  72. if (!int.TryParse(GetSessionCookieValue(BZSessionCookieConst.LoginPwdErrorKey), out error))
  73. {
  74. error = 0;
  75. }
  76. return error;
  77. }
  78. public static void AddLoginToken(string EncryptTokenNo)
  79. {
  80. try
  81. {
  82. WriteSessionCookieValue(BZSessionCookieConst.LoginPwdErrorKey, "");
  83. WriteSessionCookieValue(BZSessionCookieConst.LoginTokenKey, EncryptTokenNo);
  84. }
  85. catch (Exception ex)
  86. {
  87. throw ex;
  88. }
  89. }
  90. public static void ClearLoginToken()
  91. {
  92. try
  93. {
  94. WriteSessionCookieValue(BZSessionCookieConst.LoginPwdErrorKey, "");
  95. WriteSessionCookieValue(BZSessionCookieConst.LoginTokenKey, "");
  96. }
  97. catch //(Exception ex)
  98. {
  99. //throw ex;
  100. }
  101. }
  102. public static void LoginPwdErrAdd()
  103. {
  104. try
  105. {
  106. int error = 0;
  107. if (!int.TryParse(GetSessionCookieValue(BZSessionCookieConst.LoginPwdErrorKey), out error))
  108. {
  109. error = 0;
  110. }
  111. WriteSessionCookieValue(BZSessionCookieConst.LoginPwdErrorKey, (error + 1).ToString());
  112. }
  113. catch (Exception ex)
  114. {
  115. throw ex;
  116. }
  117. }
  118. public static ReqInfo GetWebReqData(ReqInfo reqData)
  119. {
  120. reqData.EncryptTokenNo = GetSessionCookieValue(BZSessionCookieConst.LoginTokenKey);
  121. reqData.IPAddress = NetUtil.Ip;
  122. reqData.AppType = EAppType.PC;
  123. return reqData;
  124. }
  125. public static string GetLoginTokenNo()
  126. {
  127. var key = GetSessionCookieValue(BZSessionCookieConst.LoginTokenKey);
  128. if (string.IsNullOrWhiteSpace(key))
  129. {
  130. if (ConfigHelper.GetConfig().IsSSO)
  131. {
  132. var token = WebUtil.GetItem("EncryptTokenNo");
  133. if (token != null)
  134. {
  135. key = token as string;
  136. }
  137. }
  138. else
  139. {
  140. var userId = WebUtil.GetItem("userId");
  141. if (userId != null)
  142. {
  143. key = userId as string;
  144. }
  145. }
  146. }
  147. return key;
  148. }
  149. public static string GetBodyUITheme()
  150. {
  151. string res = "lr-uitheme-top";
  152. return res;
  153. //string wms_UItheme = WebUtil.GetCookie("WMS_UItheme");
  154. //switch (wms_UItheme)
  155. //{
  156. // case "1":
  157. // res = "lr-uitheme-default"; // 经典版本
  158. // break;
  159. // case "2":
  160. // res = "lr-uitheme-accordion"; // 手风琴版本
  161. // break;
  162. // case "3":
  163. // res = "lr-uitheme-windos"; // Windos版本
  164. // break;
  165. // case "4":
  166. // res = "lr-uitheme-top"; // 顶部菜单版本
  167. // break;
  168. // default:
  169. // res = "lr-uitheme-default"; // 经典版本
  170. // break;
  171. //}
  172. //return res;
  173. }
  174. public static string GetMainUITheme()
  175. {
  176. string res = "AdminTop";
  177. return res;
  178. //string wms_UItheme = WebUtil.GetCookie("WMS_UItheme");
  179. //switch (wms_UItheme)
  180. //{
  181. // case "1":
  182. // res="AdminDefault"; // 经典版本
  183. // case "2":
  184. // res = "AdminAccordion"; // 手风琴版本
  185. // case "3":
  186. // res = "AdminWindos"; // Windos版本
  187. // case "4":
  188. // res = "AdminTop"; // 顶部菜单版本
  189. // default:
  190. // res = "AdminDefault"; // 经典版本
  191. //}
  192. }
  193. public static string GetLoginUITheme()
  194. {
  195. string res = "Top";
  196. return res;
  197. //string wms_UItheme = WebUtil.GetCookie("WMS_UItheme");
  198. //switch (wms_UItheme)
  199. //{
  200. // case "1":
  201. // res="Default"; // 经典版本
  202. // case "2":
  203. // res = "Accordion"; // 手风琴版本
  204. // case "3":
  205. // res = "Window"; // Windos版本
  206. // case "4":
  207. // res = "Top"; // 顶部菜单版本
  208. // default:
  209. // res = "Default"; // 经典版本
  210. //}
  211. }
  212. }
  213. }