コード例 #1
0
ファイル: Session.cs プロジェクト: lsmolic/hangoutsrc
        public static Dictionary <string, string> GetRoomContexts(string userCookieValue)
        {
            try
            {
                if (userCookieValue != "")
                {
                    SimpleCrypto cryptographer = new SimpleCrypto();
                    userCookieValue = cryptographer.TDesDecrypt(userCookieValue);

                    Dictionary <string, string> userContexts = new Dictionary <string, string>();

                    if (userCookieValue != null && userCookieValue != "")
                    {
                        string[] userContext = userCookieValue.Split('&');
                        foreach (string con in userContext)
                        {
                            string roomId      = con.Split('=')[0];
                            string roomContext = con.Split('=')[1];
                            userContexts.Add(roomId, roomContext);
                        }
                        return(userContexts);
                    }
                }
                return(new Dictionary <string, string>());
            }
            catch (System.Exception)
            {
                return(null);
            }
        }
コード例 #2
0
        public void SetAddCookieUserOnRampTracking(string name, string value)
        {
            string cookieValue = "";

            if (name == null)
            {
                cookieValue = value;
            }
            else if (name.Length > 0)
            {
                cookieValue = "||" + name + "-->" + value;
            }
            else
            {
                cookieValue = value;
            }

            HttpCookie   existsCookie  = HttpContext.Current.Request.Cookies.Get("onRampTracking");
            SimpleCrypto cryptographer = new SimpleCrypto();

            if (existsCookie != null)
            {
                string currentCookie = cryptographer.TDesDecrypt(existsCookie.Value).Trim();
                if (currentCookie.Contains(cookieValue.Trim()))
                {
                    cookieValue = currentCookie;
                }
                else
                {
                    cookieValue = currentCookie + "||" + cookieValue;
                }
            }

            cookieValue = cryptographer.TDesEncrypt(cookieValue);

            HttpCookie newOnRampTrackingCookie = new HttpCookie("onRampTracking", cookieValue);

            newOnRampTrackingCookie.Domain = ConfigurationManager.AppSettings["domain"];

            if (existsCookie == null)
            {
                HttpContext.Current.Response.Cookies.Add(newOnRampTrackingCookie);
                HttpContext.Current.Request.Cookies.Add(newOnRampTrackingCookie);
            }
            else
            {
                HttpContext.Current.Response.Cookies.Set(newOnRampTrackingCookie);
                HttpContext.Current.Request.Cookies.Set(newOnRampTrackingCookie);
            }
        }
コード例 #3
0
ファイル: Session.cs プロジェクト: lsmolic/hangoutsrc
        public static UserId GetCurrentUser(string userCookieValue)
        {
            try
            {
                if (userCookieValue != null)
                {
                    if (userCookieValue != "")
                    {
                        SimpleCrypto cryptographer = new SimpleCrypto();
                        userCookieValue = cryptographer.TDesDecrypt(userCookieValue);
                        int id = System.Convert.ToInt32(userCookieValue.Substring(0, userCookieValue.IndexOf(cookieToken)));

                        DateTime expiration = DateTime.Parse(userCookieValue.Substring(userCookieValue.IndexOf(cookieToken) + 2));

                        if (expiration < DateTime.Now || id == 0)
                        {
                            return(null);
                        }
                        else
                        {
                            return(new UserId(id));
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (System.Exception)
            {
                return(null);
            }
        }