private void fbLogin(HttpContext context) { string token = context.Request.Params["token"]; Facebook.FacebookClient client = new Facebook.FacebookClient(token); //client.Post() client.UseFacebookBeta = client.IsSecureConnection = true; Facebook.JsonObject o = (Facebook.JsonObject)client.Get("/me"); var db = new PetaPoco.Database(Common.HairStyleConnectionString, "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(); } } }
private void fbLogin(HttpContext context) { string token = context.Request.Params["token"]; Facebook.FacebookClient client = new Facebook.FacebookClient(token); //client.Post() client.UseFacebookBeta = client.IsSecureConnection = true; Facebook.JsonObject o = (Facebook.JsonObject)client.Get("/me"); var db = new PetaPoco.Database(Common.HairStyleConnectionString, "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(); } } }