示例#1
0
        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <returns></returns>
        public static UserTicketInfo GetUserCookie()
        {
            object obj       = WHCache.Default.Get <CookiesCache>(AppConfig.UserLoginCacheKey);
            string plaintext = string.Empty;

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

            //if( obj == null )
            //{
            //    // 大厅Cookie存在
            //    if( pfCookieUserName != null && pfCookieUserID != null )
            //    {
            //        plaintext = PalaformWriteCookie();
            //    }
            //}
            //else
            //{
            //    // 如果网页与大厅cookie都存在,验证是否一致
            //    plaintext = obj.ToString();
            //    string tempStr = Utils.AES.Decrypt( plaintext, AppConfig.UserLoginCacheEncryptKey );
            //    if( !string.IsNullOrEmpty( tempStr ) && pfCookieUserName != null && pfCookieUserID != null )
            //    {
            //        UserTicketInfo tempModel = UserTicketInfo.DeserializeObject( tempStr );
            //        if( tempModel.UserID.ToString() != pfCookieUserID.ToString() || tempModel.Accounts != pfCookieUserName.ToString() )
            //        {
            //            WHCache.Default.Delete<CookiesCache>( AppConfig.UserLoginCacheKey );
            //            plaintext = PalaformWriteCookie();
            //        }
            //    }
            //}

            if (obj == null)
            {
                return(null);
            }
            plaintext = obj.ToString();

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

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

            return(UserTicketInfo.DeserializeObject(jsonText));
        }
示例#2
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));
        }
示例#3
0
        public static UserTicketInfo GetUserCookie()
        {
            object obj   = WHCache.Default.Get <CookiesCache>(AppConfig.UserLoginCacheKey);
            string empty = string.Empty;

            if (obj == null)
            {
                return(null);
            }
            empty = obj.ToString();
            string str = AES.Decrypt(empty, AppConfig.UserLoginCacheEncryptKey);

            if (TextUtility.EmptyTrimOrNull(str))
            {
                return(null);
            }
            return(UserTicketInfo.DeserializeObject(str));
        }
示例#4
0
        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <returns></returns>
        public static UserTicketInfo GetUserCookie()
        {
            string plaintext = Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN);

            //平台跳转判断是否登录
            if (HttpContext.Current.Request.Cookies["Accounts"] != null && HttpContext.Current.Request.Cookies["Password"] != null && TextUtility.EmptyTrimOrNull(plaintext))
            {
                string accounts = HttpContext.Current.Request.Cookies["Accounts"].Value.ToString();
                string password = HttpContext.Current.Request.Cookies["Password"].Value.ToString();
                password = password.Trim();
                accounts = accounts.Trim();
                UserInfo suInfo = new UserInfo(0, accounts, 0, password.Trim());
                suInfo.LastLogonIP = GameRequest.GetUserIP();
                AccountsFacade accountsFacade = new AccountsFacade();
                Message        umsg           = accountsFacade.Logon(suInfo, true);
                if (umsg.Success)
                {
                    UserInfo ui = umsg.EntityList[0] as UserInfo;
                    ui.LogonPass = password.Trim();
                    Fetch.SetUserCookie(ui.ToUserTicketInfo());
                    plaintext = Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN);
                }
            }

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

            string jsonText = Utils.AES.Decrypt(plaintext, CookieEncryptKey);

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

            return(UserTicketInfo.DeserializeObject(jsonText));
        }