Example #1
0
        private void context_EndRequest(object sender, EventArgs e)
        {
            HttpApplication context = (HttpApplication)sender;

            if (!CookieUtil.CookieExists("session"))
            {
                CookieUtil.WriteCookie("session", JsonConvert.SerializeObject(new { id = Common.GetHash(Guid.NewGuid().ToString()), app = "nails" }), false);
            }
        }
Example #2
0
        private void fbLogin(HttpContext context)
        {
            string token = context.Request.Params["token"];

            Facebook.FacebookClient client = new Facebook.FacebookClient(token);
            //client.Post()
            Facebook.JsonObject o = (Facebook.JsonObject)client.Get("/me");
            var db = new PetaPoco.Database(Common.NailsProdConnectionString, "System.Data.SqlClient");

            using (var scope = db.GetTransaction())
            {
                try
                {
                    string         first_name = (string)o["first_name"];
                    string         name       = (string)o["name"];
                    decimal        id         = Convert.ToDecimal(o["id"]);
                    POCOS.Facebook fb         = new POCOS.Facebook();
                    fb.name       = name;
                    fb.first_name = first_name;
                    fb.gender     = (string)o["gender"];
                    fb.id         = id;
                    fb.last_name  = (string)o["last_name"];
                    fb.link       = (string)o["link"];
                    fb.locale     = (string)o["locale"];
                    fb.timezone   = Convert.ToDouble(o["timezone"]);
                    string   updatedtime = (string)o["updated_time"];
                    DateTime dt;
                    if (DateTime.TryParse(updatedtime, out dt))
                    {
                        fb.updated_time = dt;
                    }
                    if (db.Exists <POCOS.Facebook>(id))
                    {
                        db.Update(fb);
                    }
                    else
                    {
                        db.Insert(fb);
                    }
                    POCOS.AppUser au = POCOS.AppUser.FirstOrDefault("Select top 1 * from AppUsers where facebookid=@0", id);
                    if (au == null)
                    {
                        au            = new POCOS.AppUser();
                        au.FirstName  = first_name;
                        au.facebookid = id;
                        db.Insert(au);
                    }
                    scope.Complete();
                    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);
                }
                finally
                {
                    scope.Dispose();
                }
            }
        }
Example #3
0
        private void Login(HttpContext context)
        {
            string user = context.Request.Params["user"];
            string pass = context.Request.Params["pass"];

            Nails.edmx.User obj = this.GetNailsProdContext.User.FirstOrDefault(o => o.Name == user && o.Password == pass);
            if (obj != null)
            {
                CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { obj.ID }), Common.DefaultPassword), false);
                CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { obj.Name }), false);
                context.Response.Write("success");
            }
        }
Example #4
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);
            }
        }
Example #5
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);
        }
Example #6
0
        private void Invite(HttpContext context)
        {
            string invite = context.Request.QueryString["s"];

            if (!string.IsNullOrEmpty(invite))
            {
                Nails.edmx.AppUsers au = GetNailsProdContext.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);
                }
            }
        }
Example #7
0
 private void SaveProfile(HttpContext context)
 {
     Nails.edmx.AppUsers u = this.GetNailsProdContext.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;
         GetNailsProdContext.SaveChanges();
         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);
     }
 }
Example #8
0
        private void AppLogin(HttpContext context)
        {
            string user  = context.Request.Params["user"];
            string pass  = context.Request.Params["pass"];
            string match = Common.GetHash(pass);

            SubSonic.POCOS.AppUser obj = SubSonic.POCOS.AppUser.SingleOrDefault(o => o.Email == user);
            if (obj == null)
            {
                context.Response.WriteError("無效的電子郵件地址和/或密碼");
            }
            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);
            }
        }