Esempio n. 1
0
        private void context_EndRequest(object sender, EventArgs e)
        {
            HttpApplication context = (HttpApplication)sender;

            if (!CookieUtil.CookieExists(Common.sessioncookie))
            {
                CookieUtil.WriteCookie(Common.sessioncookie, JsonConvert.SerializeObject(new
                {
                    id  = Common.GetHash(Guid.NewGuid().ToString()),
                    app = "hairstyle",
                    pts = new { total = 0, ids = new int[0] }
                }), false);
            }
        }
Esempio 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);
            }
        }
Esempio 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);
        }
Esempio n. 4
0
        private void Invite(HttpContext context)
        {
            string invite = context.Request.QueryString["s"];

            if (!string.IsNullOrEmpty(invite))
            {
                HairStyle.dbml.AppUsers au = GetHairStyleContext2.AppUsers.FirstOrDefault(o1 => o1.Invite == invite);
                if (au != null)
                {
                    CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = au.ID }), Common.DefaultPassword), false);
                    CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { email = au.Email, name = au.Name, avatar = string.IsNullOrWhiteSpace(au.Avatar) ? null : Common.UploadedImageRelPath + au.Avatar }), false);
                    context.Response.Redirect("~/home#settings", false);
                }
            }
        }
Esempio n. 5
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);
 }
Esempio n. 6
0
 private void SaveProfile(HttpContext context)
 {
     HairStyle.dbml.AppUsers u = this.GetHairStyleContext2.AppUsers.First(o => o.ID == Common.UserID);
     if (string.IsNullOrEmpty(u.Password))
     {
         context.Response.WriteError("Password not updated");
     }
     else
     {
         string email      = context.Request.Params["email"];
         string first_name = context.Request.Params["first_name"];
         string about      = context.Request.Params["about"];
         string location   = context.Request.Params["location"];
         string fn         = context.Request.Params["fn"];
         string website    = context.Request.Params["website"];
         string name       = context.Request.Params["name"];
         if (!string.IsNullOrEmpty(fn))
         {
             Uri      uri          = new Uri(fn);
             string   filename     = uri.Segments.Last();
             string   fp           = Path.Combine(Common.Temp, Common.UserID.ToString(), filename);
             string   uploadedpath = Common.UploadedImagePath;
             FileInfo fInfo        = new FileInfo(fp);
             string   nfn          = fInfo.Name;
             if (fInfo.DirectoryName != uploadedpath)
             {
                 string dest = Path.Combine(uploadedpath, nfn);
                 fInfo.MoveTo(dest);
             }
             u.Avatar = nfn;
         }
         u.Location  = location;
         u.Email     = email;
         u.FirstName = first_name;
         u.Website   = website;
         u.Location  = location;
         u.About     = about;
         u.Name      = name;
         GetHairStyleContext2.SubmitChanges();
         CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = u.ID }), Common.DefaultPassword), false);
         CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { email = u.Email, name = u.Name, avatar = string.IsNullOrWhiteSpace(u.Avatar) ? null : Common.UploadedImageRelPath + u.Avatar }), false);
     }
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     Response.Cache.SetNoStore();
     Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
     Common.RemoveValueinCookie(Common.InfoCookie, new string[] {
         "vuID",
         "vuemail",
         "vuname",
         "vuavatar"
     });
     if (CookieUtil.CookieExists(Common.AuthCookie))
     {
         Response.WriteFile("LoggedIn.html");
     }
     else
     {
         Response.WriteFile("home.html");
     }
     Response.End();
 }