Ejemplo n.º 1
0
 public static string ReadValue(string cookieName, string propertyName)
 {
     if (CookieUtil.CookieExists(cookieName))
     {
         JObject _cookie = JObject.Parse(context.Server.UrlDecode(CookieUtil.ReadCookie(cookieName)));
         JToken  tok     = _cookie[propertyName];
         return((tok == null) || (tok.Type == JTokenType.Null) || (tok.Type == JTokenType.Undefined) || (tok.Type == JTokenType.None) ? null : _cookie[propertyName].ToString().Trim('"'));
     }
     return(null);
 }
Ejemplo n.º 2
0
        public static void RemoveValueinCookie(string cookieName, string[] values)
        {
            string json = context.Server.UrlDecode(CookieUtil.ReadCookie(cookieName));

            if (!string.IsNullOrEmpty(json))
            {
                JObject obj = JObject.Parse(json);
                foreach (string tk in values)
                {
                    obj.Remove(tk);
                }
                CookieUtil.WriteCookie(cookieName, obj.ToString(), false);
            }
        }
Ejemplo n.º 3
0
        public static void UpdateCookie(string cookieName, JObject values)
        {
            string json = context.Server.UrlDecode(CookieUtil.ReadCookie(cookieName));

            if (!string.IsNullOrEmpty(json))
            {
                JObject obj = JObject.Parse(json);
                foreach (var tk in obj)
                {
                    values[tk.Key] = tk.Value;
                }
            }
            CookieUtil.WriteCookie(cookieName, values.ToString(), false);
        }
Ejemplo n.º 4
0
 public static string ReadValue(string cookieName, string propertyName, bool decrypt)
 {
     if (CookieUtil.CookieExists(cookieName))
     {
         JObject _cookie;
         if (decrypt)
         {
             string val = EncDec.Decrypt(CookieUtil.ReadCookie(cookieName), DefaultPassword);
             _cookie = JObject.Parse(val);
             JToken tok = _cookie[propertyName];
             return((tok == null) || (tok.Type == JTokenType.Null) || (tok.Type == JTokenType.Undefined) || (tok.Type == JTokenType.None) ? null : _cookie[propertyName].ToString().Trim('"'));
         }
         return(ReadValue(cookieName, propertyName));
     }
     return(null);
 }
Ejemplo n.º 5
0
        private void AppLogin(HttpContext context)
        {
            string user  = context.Request.Params["user"];
            string pass  = context.Request.Params["pass"];
            string match = Common.GetHash(pass);
            var    obj   = (from o in GetHairStyleContext2.AppUsers
                            where (o.Email == user || o.Name == user) && o.Password == match
                            select new
            {
                o.Email,
                o.Name,
                o.Avatar,
                o.ID
            }).SingleOrDefault();

            if (obj == null)
            {
                context.Response.Write("Invalid Email Address and/or Password");
            }
            else
            {
                CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = obj.ID }), Common.DefaultPassword), false);
                CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new
                {
                    email  = obj.Email,
                    name   = obj.Name,
                    avatar = string.IsNullOrWhiteSpace(obj.Avatar) ? null : Common.UploadedImageRelPath + obj.Avatar
                }), false);
                GetHairStyleContext3.UpdatePoints(obj.ID, Common.SessionID).Execute();
                JObject jobj   = JObject.Parse(context.Server.UrlDecode(CookieUtil.ReadCookie(Common.sessioncookie)));
                int?    points = (from o in GetHairStyleContext4.AppUsers where o.ID == obj.ID select o.Points).First();
                var     ids    = (from o in GetHairStyleContext4.Reviews where o.ID == obj.ID select o.BIMID);
                jobj["pts"] = JObject.FromObject(new
                {
                    ids,
                    total = points
                });
                CookieUtil.WriteCookie(Common.sessioncookie, jobj.ToString(), false);
            }
        }