예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
        /// <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.Mall_USER, cookieValue, expiredTime.Value);
            }
            else
            {
                WebHelper.SetCookie(CookieKeysCollection.Mall_USER, cookieValue);
            }
        }
예제 #4
0
 /// <summary>
 /// 解析userKey
 /// </summary>
 /// <param name="userKey"></param>
 /// <returns></returns>
 protected virtual long DecryptUserKey(string userKey)
 {
     return(UserCookieEncryptHelper.Decrypt(userKey, CookieKeysCollection.USERROLE_USER));
 }
예제 #5
0
        public static Entities.MemberInfo GetUser(HttpRequest request)
        {
            /*
             * long id = UserCookieEncryptHelper.Decrypt(WebHelper.GetCookie("Mall-User"), "2");
             * if (id == 0L)
             * {
             *  string userIdCookie = request.Query["token"].ToString();
             *  //string userIdCookie = Guid.NewGuid().ToString();
             *  id = UserCookieEncryptHelper.Decrypt(userIdCookie, "2");
             *  if (id != 0L)
             *  {
             *      WebHelper.SetCookie("Mall-User", userIdCookie);
             *  }
             * }
             * if (id != 0L)
             * {
             *  var userInfo = MemberApplication.GetMember(id);
             *  var siteInfo = SiteSettingApplication.SiteSettings;
             *  if (siteInfo != null)
             *  {
             *      if (!(siteInfo.IsOpenPC || siteInfo.IsOpenH5 || siteInfo.IsOpenMallSmallProg || siteInfo.IsOpenApp))//授权模块影响会员折扣功能
             *      {
             *          userInfo.MemberDiscount = 1M;
             *      }
             *
             *  }
             *  return userInfo;
             * }
             * return null;
             *
             */


            long userId = 0;
            var  token  = request.Query["token"].ToString();

            if (!string.IsNullOrEmpty(token))
            {
                userId = UserCookieEncryptHelper.Decrypt(token, CookieKeysCollection.USERROLE_USER);
                if (userId != 0)
                {
                    WebHelper.SetCookie(CookieKeysCollection.Mall_USER, token);
                }
            }
            if (userId == 0)
            {
                var cookieValue = WebHelper.GetCookie(CookieKeysCollection.Mall_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);
        }