public static Entities.MemberInfo GetUser(HttpRequestBase request) { long userId = 0; var token = request.QueryString["token"]; if (!string.IsNullOrEmpty(token)) { userId = UserCookieEncryptHelper.Decrypt(token, CookieKeysCollection.USERROLE_USER); if (userId != 0) { WebHelper.SetCookie(CookieKeysCollection.HIMALL_USER, token); } } if (userId == 0) { var cookieValue = WebHelper.GetCookie(CookieKeysCollection.HIMALL_USER); userId = UserCookieEncryptHelper.Decrypt(cookieValue, CookieKeysCollection.USERROLE_USER); } if (userId != 0) { var userInfo = MemberApplication.GetMember(userId); var siteInfo = SiteSettingApplication.SiteSettings; if (siteInfo != null) { if (!(siteInfo.IsOpenPC || siteInfo.IsOpenH5 || siteInfo.IsOpenMallSmallProg || siteInfo.IsOpenApp))//授权模块影响会员折扣功能 { userInfo.MemberDiscount = 1M; } } return(userInfo); } return(null); }
protected virtual void SetUserLoginCookie(long userId, DateTime?expiredTime = new DateTime?()) { string str = UserCookieEncryptHelper.Encrypt(userId, "2"); if (expiredTime.HasValue) { WebHelper.SetCookie("Himall-User", str, expiredTime.Value); } else { WebHelper.SetCookie("Himall-User", str); } }
protected virtual void SetSellerAdminLoginCookie(long sellerAdminId, DateTime?expiredTime = new DateTime?()) { string str = UserCookieEncryptHelper.Encrypt(sellerAdminId, "1"); if (expiredTime.HasValue) { WebHelper.SetCookie("Himall-SellerManager", str, expiredTime.Value); } else { WebHelper.SetCookie("Himall-SellerManager", str); } }
/// <summary> /// 设置SellerAdmin登录cookie /// </summary> /// <param name="sellerAdminId">SellerAdmin的id</param> /// <param name="expiredTime">cookie过期时间</param> protected virtual void SetSellerAdminLoginCookie(long sellerAdminId, DateTime?expiredTime = null) { var cookieValue = UserCookieEncryptHelper.Encrypt(sellerAdminId, CookieKeysCollection.USERROLE_SELLERADMIN); if (expiredTime.HasValue) { WebHelper.SetCookie(CookieKeysCollection.SELLER_MANAGER, cookieValue, expiredTime.Value); } else { WebHelper.SetCookie(CookieKeysCollection.SELLER_MANAGER, cookieValue); } }
/// <summary> /// 设置普通用户登录cookie /// </summary> /// <param name="userId">登录用户的id</param> /// <param name="expiredTime">cookie过期时间</param> protected virtual void SetUserLoginCookie(long userId, DateTime?expiredTime = null) { var cookieValue = UserCookieEncryptHelper.Encrypt(userId, CookieKeysCollection.USERROLE_USER); if (expiredTime.HasValue) { WebHelper.SetCookie(CookieKeysCollection.HIMALL_USER, cookieValue, expiredTime.Value); } else { WebHelper.SetCookie(CookieKeysCollection.HIMALL_USER, cookieValue); } }
/// <summary> /// 设置Admin登录cookie /// </summary> /// <param name="adminId">Admin的id</param> /// <param name="expiredTime">cookie过期时间</param> protected virtual void SetAdminLoginCookie(long adminId, DateTime?expiredTime = null) { var cookieValue = UserCookieEncryptHelper.Encrypt(adminId, CookieKeysCollection.USERROLE_ADMIN, 1); if (expiredTime.HasValue) { WebHelper.SetCookie(CookieKeysCollection.PLATFORM_MANAGER, cookieValue, expiredTime.Value); } else { WebHelper.SetCookie(CookieKeysCollection.PLATFORM_MANAGER, cookieValue); } }
public static UserMemberInfo GetUser(HttpRequestBase request) { long id = UserCookieEncryptHelper.Decrypt(WebHelper.GetCookie("Himall-User"), "2"); if (id == 0L) { string userIdCookie = request.QueryString["token"]; id = UserCookieEncryptHelper.Decrypt(userIdCookie, "2"); if (id != 0L) { WebHelper.SetCookie("Himall-User", userIdCookie); } } if (id != 0L) { return(MemberApplication.GetUserByCache(id)); } return(null); }
public static UserMemberInfo GetUser(HttpRequestBase request) { var cookieValue = WebHelper.GetCookie(CookieKeysCollection.HIMALL_USER); var userId = UserCookieEncryptHelper.Decrypt(cookieValue, CookieKeysCollection.USERROLE_USER); if (userId == 0) { var token = request.QueryString["token"]; userId = UserCookieEncryptHelper.Decrypt(token, CookieKeysCollection.USERROLE_USER); if (userId != 0) { WebHelper.SetCookie(CookieKeysCollection.HIMALL_USER, token); } } if (userId != 0) { return(Application.MemberApplication.GetUserByCache(userId)); } return(null); }
/// <summary> /// 解析userKey /// </summary> /// <param name="userKey"></param> /// <returns></returns> protected virtual long DecryptUserKey(string userKey) { return(UserCookieEncryptHelper.Decrypt(userKey, CookieKeysCollection.USERROLE_USER)); }
private bool BindOpenIdToUser(ActionExecutingContext filterContext) { string str; bool flag = true; IMobileOAuth weixinOAuth = null; if (base.PlatformType == Himall.Core.PlatformType.WeiXin) { weixinOAuth = new WeixinOAuth(); } string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString())); if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != Himall.Core.PlatformType.WeiXin) { flag = false; } else { WXShopInfo wXShopInfo = new WXShopInfo(); string item = filterContext.HttpContext.Request["shop"]; MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal; if (!string.IsNullOrEmpty(item)) { long num = 0; long.TryParse(item, out num); if (num > 0) { wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num); } } if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret)) { WXShopInfo wXShopInfo1 = new WXShopInfo() { AppId = base.CurrentSiteSetting.WeixinAppId, AppSecret = base.CurrentSiteSetting.WeixinAppSecret, Token = base.CurrentSiteSetting.WeixinToken }; wXShopInfo = wXShopInfo1; appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment; } MobileOAuthUserInfo userInfoBequiet = weixinOAuth.GetUserInfo_bequiet(filterContext, out str, wXShopInfo); if (!string.IsNullOrWhiteSpace(str)) { filterContext.Result = Redirect(str); } else { flag = false; if (userInfoBequiet != null && !string.IsNullOrWhiteSpace(userInfoBequiet.OpenId)) { if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment) { string str1 = SecureHelper.AESEncrypt(userInfoBequiet.OpenId, "Mobile"); WebHelper.SetCookie("Himall-User_OpenId", str1); } IMemberService memberService = ServiceHelper.Create <IMemberService>(); UserMemberInfo memberByOpenId = null; if (memberByOpenId == null) { memberByOpenId = memberService.GetMemberByOpenId(userInfoBequiet.LoginProvider, userInfoBequiet.OpenId); } if (memberByOpenId == null) { memberService.BindMember(base.CurrentUser.Id, "Himall.Plugin.OAuth.WeiXin", userInfoBequiet.OpenId, appIdTypeEnum, null, userInfoBequiet.UnionId); } else { string str2 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile"); WebHelper.SetCookie("Himall-User", str2); } } } } return(flag); }
private bool ProcessInvalidUser_NormalRequest(ActionExecutingContext filterContext) { string str; bool flag = true; IMobileOAuth weixinOAuth = null; if (base.PlatformType == Himall.Core.PlatformType.WeiXin) { weixinOAuth = new WeixinOAuth(); } string str1 = string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString())); if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != Himall.Core.PlatformType.WeiXin) { filterContext.Result = Redirect(str1); } else { WXShopInfo wXShopInfo = new WXShopInfo(); string item = filterContext.HttpContext.Request["shop"]; MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal; if (!string.IsNullOrEmpty(item)) { long num = 0; long.TryParse(item, out num); if (num > 0) { wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num); } } if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret)) { WXShopInfo wXShopInfo1 = new WXShopInfo() { AppId = base.CurrentSiteSetting.WeixinAppId, AppSecret = base.CurrentSiteSetting.WeixinAppSecret, Token = base.CurrentSiteSetting.WeixinToken }; wXShopInfo = wXShopInfo1; appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment; } MobileOAuthUserInfo userInfo = weixinOAuth.GetUserInfo(filterContext, out str, wXShopInfo); if (!string.IsNullOrWhiteSpace(str)) { filterContext.Result = Redirect(str); } else if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.OpenId)) { filterContext.Result = Redirect(str1); } else { if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment) { string str2 = SecureHelper.AESEncrypt(userInfo.OpenId, "Mobile"); WebHelper.SetCookie("Himall-User_OpenId", str2); } UserMemberInfo memberByOpenId = null; if (memberByOpenId == null) { memberByOpenId = ServiceHelper.Create <IMemberService>().GetMemberByOpenId(userInfo.LoginProvider, userInfo.OpenId); } if (memberByOpenId == null) { object[] objArray = new object[] { base.PlatformType.ToString(), userInfo.OpenId, "Himall.Plugin.OAuth.WeiXin", HttpUtility.UrlEncode(userInfo.NickName), HttpUtility.UrlEncode(userInfo.RealName), HttpUtility.UrlEncode(userInfo.Headimgurl), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()), appIdTypeEnum, userInfo.UnionId }; str1 = string.Format("/m-{0}/Login/Entrance?openId={1}&serviceProvider={2}&nickName={3}&realName={4}&headimgurl={5}&returnUrl={6}&AppidType={7}&unionid={8}", objArray); filterContext.Result = Redirect(str1); } else { string str3 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile"); WebHelper.SetCookie("Himall-User", str3); } } } return(flag); }