using System; using WMS.Util; using WMS.Info; using WMS.BZUtil; namespace WMS.Core { /// /// 获取登录用户信息 /// public class SessionCookieCore { public static string GetSessionCookieValue(string Key) { try { if (SysSetCore.GetSysSet().IsSession) { return WebUtil.GetSession(Key); } else { return WebUtil.GetCookie(Key); } } catch { } return ""; } public static void WriteSessionCookieValue(string Key, string Value) { try { if (SysSetCore.GetSysSet().IsSession) { WebUtil.WriteSession(Key, Value); } else { WebUtil.WriteCookie(Key, Value, 60 * 5); } } catch (Exception ex) { //throw ex; } } public static void CheckVerifyCode(string VerifyCode) { try { if (GetUserPwdErrorNum() >= 3) { if (string.IsNullOrWhiteSpace(VerifyCode)) { throw SysExCore.ThrowFailException("验证码为空。"); } if (VerifyCode.ToUpper() != GetSessionCookieValue(SessionCookieConst.LoginVerifyCodeKey).ToUpper()) { throw SysExCore.ThrowFailException("验证码错误。"); } } } catch (Exception ex) { throw ex; } } public static int GetUserPwdErrorNum() { int error = 0; if (!int.TryParse(GetSessionCookieValue(SessionCookieConst.LoginPwdErrorKey), out error)) { error = 0; } return error; } public static void AddLoginToken(string EncryptTokenNo) { try { WriteSessionCookieValue(SessionCookieConst.LoginPwdErrorKey, ""); WriteSessionCookieValue(SessionCookieConst.LoginTokenKey, EncryptTokenNo); } catch (Exception ex) { throw ex; } } public static void ClearLoginToken() { try { WriteSessionCookieValue(SessionCookieConst.LoginPwdErrorKey, ""); WriteSessionCookieValue(SessionCookieConst.LoginTokenKey, ""); } catch //(Exception ex) { //throw ex; } } public static void LoginPwdErrAdd() { try { int error = 0; if (!int.TryParse(GetSessionCookieValue(SessionCookieConst.LoginPwdErrorKey), out error)) { error = 0; } WriteSessionCookieValue(SessionCookieConst.LoginPwdErrorKey, (error + 1).ToString()); } catch (Exception ex) { throw ex; } } public static ReqInfo GetWebReqData(ReqInfo reqData) { reqData.EncryptTokenNo = GetSessionCookieValue(SessionCookieConst.LoginTokenKey); reqData.IPAddress = NetUtil.Ip; reqData.AppType = EAppType.PC; return reqData; } public static string GetLoginTokenNo() { var key = GetSessionCookieValue(SessionCookieConst.LoginTokenKey); if (string.IsNullOrWhiteSpace(key)) { if (ConfigHelper.GetConfig().IsSSO) { var token = WebUtil.GetItem("EncryptTokenNo"); if (token != null) { key = token as string; } } else { var userId = WebUtil.GetItem("userId"); if (userId != null) { key = userId as string; } } } return key; } public static string GetBodyUITheme() { string res = "lr-uitheme-top"; return res; //string wms_UItheme = WebUtil.GetCookie("WMS_UItheme"); //switch (wms_UItheme) //{ // case "1": // res = "lr-uitheme-default"; // 经典版本 // break; // case "2": // res = "lr-uitheme-accordion"; // 手风琴版本 // break; // case "3": // res = "lr-uitheme-windos"; // Windos版本 // break; // case "4": // res = "lr-uitheme-top"; // 顶部菜单版本 // break; // default: // res = "lr-uitheme-default"; // 经典版本 // break; //} //return res; } public static string GetMainUITheme() { string res = "AdminTop"; return res; //string wms_UItheme = WebUtil.GetCookie("WMS_UItheme"); //switch (wms_UItheme) //{ // case "1": // res="AdminDefault"; // 经典版本 // case "2": // res = "AdminAccordion"; // 手风琴版本 // case "3": // res = "AdminWindos"; // Windos版本 // case "4": // res = "AdminTop"; // 顶部菜单版本 // default: // res = "AdminDefault"; // 经典版本 //} } public static string GetLoginUITheme() { string res = "Top"; return res; //string wms_UItheme = WebUtil.GetCookie("WMS_UItheme"); //switch (wms_UItheme) //{ // case "1": // res="Default"; // 经典版本 // case "2": // res = "Accordion"; // 手风琴版本 // case "3": // res = "Window"; // Windos版本 // case "4": // res = "Top"; // 顶部菜单版本 // default: // res = "Default"; // 经典版本 //} } } }