示例#1
0
文件: Fetch.cs 项目: archangelwin/QY
        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <returns></returns>
        public static UserTicketInfo GetUserCookie()
        {
            string plaintext = Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN);

            // 大厅cookie处理
            object pfCookieUserName = HttpContext.Current.Request.Cookies["Accounts"];
            object pfCookieUserID   = HttpContext.Current.Request.Cookies["UserID"];

            if (string.IsNullOrEmpty(plaintext))
            {
                // 大厅Cookie存在
                if (pfCookieUserName != null && pfCookieUserID != null)
                {
                    plaintext = PalaformWriteCookie();
                }
            }
            else
            {
                // 如果网页与大厅cookie都存在,验证是否一致
                string tempStr = Utils.AES.Decrypt(plaintext, CookieEncryptKey);
                if (!string.IsNullOrEmpty(tempStr) && pfCookieUserName != null && pfCookieUserID != null)
                {
                    UserTicketInfo tempModel = UserTicketInfo.DeserializeObject(tempStr);
                    if (tempModel.UserID.ToString() != pfCookieUserID.ToString() || tempModel.Accounts != pfCookieUserName.ToString())
                    {
                        Fetch.DeleteCookie(Fetch.UC_COOKIE_LOGON_TOKEN);
                        plaintext = PalaformWriteCookie();
                    }
                }
            }

            //cookie为空
            if (TextUtility.EmptyTrimOrNull(plaintext))
            {
                return(null);
            }

            //验证cookie格式
            string jsonText = Utils.AES.Decrypt(plaintext, CookieEncryptKey);

            if (TextUtility.EmptyTrimOrNull(jsonText))
            {
                return(null);
            }

            return(UserTicketInfo.DeserializeObject(jsonText));
        }
示例#2
0
文件: Fetch.cs 项目: archangelwin/QY
 /// <summary>
 /// 删除用户cookie
 /// </summary>
 public static void DeleteUserCookie()
 {
     Fetch.DeleteCookie(Fetch.UC_COOKIE_NAME);
 }