protected void Page_Load(object sender, EventArgs e) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagGreatest); JObject user = facebook.GetObject("me", null); MixmagGreatestVoteSet vs = new MixmagGreatestVoteSet(new Query(new Q(MixmagGreatestVote.Columns.FacebookUid, facebook.Uid))); if (vs.Count > 0) { try { Update u = new Update(); u.Table = TablesEnum.MixmagGreatestDj; u.Changes.Add(new Assign.Subtraction(MixmagGreatestDj.Columns.TotalVotes, 1)); u.Where = new Q(MixmagGreatestDj.Columns.K, vs[0].MixmagGreatestDjK); u.Run(); } catch { } vs[0].Delete(); Response.Write("Done."); } else Response.Write("Nothing to delete!"); }
public static Hashtable RepostNow(int entryK, string message) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagVote); JObject user = facebook.GetObject("me", null); MixmagEntry me = new MixmagEntry(entryK); MixmagComp c = MixmagComp.GetByK(me.MixmagCompK); Hashtable ret = new Hashtable(); try { Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = me.ImageUrl; par["link"] = "http://mixmag-vote.com/" + me.K; par["name"] = c.FacebookPostName; par["caption"] = c.FacebookPostCaption; par["description"] = c.FacebookPostDescription; facebook.PutWallPost(message, par); } catch { ret["Done"] = false; return ret; } ret["Done"] = true; return ret; }
public dynamic GetObjectFromFaceBook(string token) { var facebook = new FacebookGraphAPI(token); return facebook.GetObject("me", null); }
public static Hashtable VoteNow(int entryK, int compK, string imageUrl) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagVote); JObject user = facebook.GetObject("me", null); string email = user.Value<string>("email"); string firstName = user.Value<string>("first_name"); string lastName = user.Value<string>("last_name"); MixmagComp c = null; MixmagEntry e = null; if (entryK > 0) { try { e = new MixmagEntry(entryK); } catch { } } Hashtable ret = new Hashtable(); if (e != null) { //got an entry c = MixmagComp.GetByK(e.MixmagCompK); } else if (imageUrl.Length > 0 && compK > 0) { c = MixmagComp.GetByK(compK); MixmagEntrySet mes = new MixmagEntrySet(new Query(new And(new Q(MixmagEntry.Columns.MixmagCompK, compK), new Q(MixmagEntry.Columns.ImageUrl, imageUrl)))); if (mes.Count > 0) { e = mes[0]; } else { //create a new skeleton entry for this image e = new MixmagEntry(); e.DateTime = DateTime.Now; e.Email = ""; e.FacebookUid = 0; e.FirstName = ""; e.LastName = ""; e.ImageUrl = imageUrl; e.MixmagCompK = c.K; e.Update(); } } else { ret["Done"] = false; ret["Message"] = "Can't find this entry."; return ret; } if (!c.Enabled) { ret["Done"] = false; ret["Message"] = "This competition isn't enabled."; return ret; } if (DateTime.Now > c.EndDate) { ret["Done"] = false; ret["Message"] = "This competition is now closed."; return ret; } if (DateTime.Now < c.StartDate) { ret["Done"] = false; ret["Message"] = "This competition hasn't started yet."; return ret; } if (e.K > 0) { Query q = new Query( new And( new Q(Bobs.MixmagVote.Columns.MixmagEntryK, e.K), new Q(Bobs.MixmagVote.Columns.FacebookUID, facebook.Uid) ) ); q.ReturnCountOnly = true; MixmagVoteSet mes = new MixmagVoteSet(q); if (mes.Count > 0) { ret["Done"] = false; ret["Message"] = "You have already voted for this photo."; return ret; } } Bobs.MixmagVote v = new Bobs.MixmagVote(); v.DateTime = DateTime.Now; v.FacebookUID = facebook.Uid; v.MixmagEntryK = e.K; v.Update(); if (e.FacebookUid.HasValue && e.FacebookUid.Value > 0 && c.FacebookVoteMessage.Length > 0) { try { Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = e.ImageUrl; par["link"] = "http://mixmag-vote.com/" + e.K; par["name"] = c.FacebookPostName; par["caption"] = c.FacebookPostCaption; par["description"] = c.FacebookPostDescription; facebook.PutWallPost(c.FacebookVoteMessage, par); } catch { } } ret["Done"] = true; ret["MixmagVoteK"] = v.K; return ret; }
public static Hashtable SaveQuestion(int entryK, int compK, string imageUrl, string questionString) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagVote); JObject user = facebook.GetObject("me", null); string email = user.Value<string>("email"); string firstName = user.Value<string>("first_name"); string lastName = user.Value<string>("last_name"); MixmagComp c = null; MixmagEntry e = null; if (entryK > 0) { try { e = new MixmagEntry(entryK); } catch { } } Hashtable ret = new Hashtable(); if (e != null) { //got an entry c = MixmagComp.GetByK(e.MixmagCompK); } else if (imageUrl.Length > 0 && compK > 0) { c = MixmagComp.GetByK(compK); MixmagEntrySet mes = new MixmagEntrySet(new Query(new And(new Q(MixmagEntry.Columns.MixmagCompK, compK), new Q(MixmagEntry.Columns.ImageUrl, imageUrl)))); if (mes.Count > 0) { e = mes[0]; } else { ret["Done"] = false; ret["Message"] = "Can't find this entry."; return ret; } } else { ret["Done"] = false; ret["Message"] = "Can't find this entry."; return ret; } if (!c.Enabled) { ret["Done"] = false; ret["Message"] = "This competition isn't enabled."; return ret; } if (DateTime.Now > c.EndDate) { ret["Done"] = false; ret["Message"] = "This competition is now closed."; return ret; } if (DateTime.Now < c.StartDate) { ret["Done"] = false; ret["Message"] = "This competition hasn't started yet."; return ret; } if (e.K == 0) { ret["Done"] = false; ret["Message"] = "Vote not found."; return ret; } Query q = new Query( new And( new Q(Bobs.MixmagVote.Columns.MixmagEntryK, e.K), new Q(Bobs.MixmagVote.Columns.FacebookUID, facebook.Uid) ) ); MixmagVoteSet mvs = new MixmagVoteSet(q); if (mvs.Count == 0) { ret["Done"] = false; ret["Message"] = "Vote not found."; return ret; } Bobs.MixmagVote v = mvs[0]; v.TextField1 = questionString; v.Update(); ret["Done"] = true; ret["MixmagVoteK"] = v.K; return ret; }
public static Hashtable VoteNow(int mixmagGreatestDjK, string facebookSource, bool facebookMessage) { try { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagGreatest); JObject user = facebook.GetObject("me", null); //string email = user.Value<string>("email"); string firstName = user.Value<string>("first_name"); string lastName = user.Value<string>("last_name"); Hashtable ret = new Hashtable(); if (DateTime.Now > new DateTime(2011, 12, 24)) { ret["Done"] = false; ret["Message"] = "Sorry, voting closed at midnight on 23rd December 2011."; return ret; } MixmagGreatestDj dj = new MixmagGreatestDj(mixmagGreatestDjK); MixmagGreatestVote mgv = new MixmagGreatestVote(); mgv.DateTime = DateTime.Now; mgv.DidWallPost = false; mgv.EmailPermission = true; //mgv.FacebookEmail = email; mgv.FacebookUid = facebook.Uid; mgv.MixmagGreatestDjK = dj.K; mgv.WallPostPermission = true; mgv.FacebookSource = facebookSource == "1"; try { if (!Vars.DevEnv && DateTime.Now > new DateTime(2011, 09, 15, 11, 0, 0)) mgv.Update(); } catch (Exception ex) { MixmagGreatestVoteSet voteSet = new MixmagGreatestVoteSet(new Query(new Q(MixmagGreatestVote.Columns.FacebookUid, facebook.Uid))); if (voteSet.Count > 0) { MixmagGreatestDj votedFor = new MixmagGreatestDj(voteSet[0].MixmagGreatestDjK); ret["Done"] = false; ret["Message"] = "You already voted for " + votedFor.Name + ". Sorry - you can only vote once."; return ret; } else { ret["Done"] = false; ret["Message"] = "There's a problem voting: " + ex.ToString(); return ret; } } try { Update u = new Update(); u.Table = TablesEnum.MixmagGreatestDj; u.Changes.Add(new Assign.Increment(MixmagGreatestDj.Columns.TotalVotes)); u.Where = new Q(MixmagGreatestDj.Columns.K, dj.K); u.Run(); } catch { } //FacebookHttpContext.Current.Status.Set(dj.Name + " is my greatest DJ of all time. Click to vote for yours in the Mixmag poll: http://greatest.dj/"); if (facebookMessage) { try { //send facebook message //http://developers.facebook.com/docs/reference/api/post Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = dj.Image90Url; par["link"] = "http://mixmag-greatest.com/?fb=1"; par["name"] = "Mixmag Greatest Dance Act"; if (dj.IsHidden) { par["description"] = "I voted for my greatest dance act of all time. Vote for yours now in the Mixmag poll..."; } else { par["caption"] = dj.Name; par["description"] = "I voted " + dj.ShortName + " the greatest dance act of all time. Vote for yours now in the Mixmag poll..."; } facebook.PutWallPost("", par); mgv.DidWallPost = true; mgv.Update(); } catch { } } ret["Done"] = true; return ret; } catch (Exception ex) { Hashtable ret = new Hashtable(); ret["Done"] = false; ret["Message"] = ex.ToString(); return ret; } }
public static void CreateNewConnect(FacebookGraphAPI facebook, int usrK) { Query q = new Query(); q.QueryCondition = new And( new Q(FacebookPost.Columns.FacebookUid, facebook.Uid), new Q(FacebookPost.Columns.Type, TypeEnum.NewConnect)); FacebookPostSet fps = new FacebookPostSet(q); if (fps.Count == 0) { FacebookPost fp = new FacebookPost(); fp.Hits = 0; fp.FacebookUid = facebook.Uid; fp.DateTime = System.DateTime.Now; fp.Type = TypeEnum.NewConnect; fp.Content = ""; fp.UsrK = usrK; fp.Update(); //send facebook message //http://developers.facebook.com/docs/reference/api/post Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = Vars.DevEnv ? "http://pix-cdn.dontstayin.com/db864428-71be-4216-9d06-d641ce992301.png" : "http://www.dontstayin.com/gfx/logo-90.png"; par["link"] = "http://www.dontstayin.com/?fbpk=" + fp.K.ToString(); par["name"] = "Don't Stay In"; facebook.PutWallPost("I've just connected to Don't Stay In...", par); } }
public static Hashtable AutoLinkByAutoLoginUsr(int autoLoginUsrK, string autoLoginUsrLoginString, Hashtable detailsPanelData) { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); JObject user = facebook.GetObject("me", null); Hashtable ret = new Hashtable(); if (autoLoginUsrK > 0) { Usr u = null; try { u = new Usr(autoLoginUsrK); } catch { } if (u != null && !u.EnhancedSecurity && u.LoginString.ToLower() == autoLoginUsrLoginString.ToLower()) { if (!u.IsEmailVerified) { u.IsEmailVerified = true; u.Update(); } ret["FacebookAutoLoginUsrMatch"] = true; linkAndLogin(u, ret, facebook, user, detailsPanelData); return ret; } } ret["FacebookAutoLoginUsrMatch"] = false; return ret; }
public static Hashtable GetUserByFacebookUID(int autoLoginUsrK, string autoLoginUsrLoginString) { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); Hashtable ret = new Hashtable(); ret["FacebookUIDMatch"] = false; ret["FacebookAutoLoginUsrMatch"] = false; ret["FacebookEmailMatch"] = false; ret["FacebookEmailMatchToCurrentUser"] = false; #region add data about the AutoLoginUsr (so we can display this if we don't end up logged in as it) if (autoLoginUsrK > 0) { Usr u = null; try { u = new Usr(autoLoginUsrK); } catch { } if (u != null) { Hashtable autoLoginUsrHash = new Hashtable(); autoLoginUsrHash["NickName"] = u.NickName; if (u.LoginString.ToLower() == autoLoginUsrLoginString.ToLower()) { autoLoginUsrHash["LoginStringMatch"] = true; autoLoginUsrHash["Email"] = u.Email; } else autoLoginUsrHash["LoginStringMatch"] = false; if (u.NickName.Length > 0) autoLoginUsrHash["Link"] = u.Link(); autoLoginUsrHash["HasNullPassword"] = u.HasNullPassword; ret["AutoLoginUsr"] = autoLoginUsrHash; } } #endregion #region try to find usr linked by UID Query qUID = new Query(); qUID.QueryCondition = new Q(Usr.Columns.FacebookUID, facebook.Uid); UsrSet usUID = new UsrSet(qUID); if (usUID.Count > 0) { Usr u = usUID[0]; if (!u.IsEmailVerified && autoLoginUsrK > 0 && autoLoginUsrK == u.K && u.LoginString.ToLower() == autoLoginUsrLoginString.ToLower()) { u.IsEmailVerified = true; u.Update(); } ret["FacebookUIDMatch"] = true; loginAndSetAuthCookie(u, ret, facebook.AccessToken); return ret; } #endregion #region if we have a forced usr (auto login link), we should link it immediatly if (autoLoginUsrK > 0) { Usr u = null; try { u = new Usr(autoLoginUsrK); } catch { } if (u != null && u.LoginString.ToLower() == autoLoginUsrLoginString.ToLower() && !u.EnhancedSecurity) { if (!u.IsEmailVerified) { u.IsEmailVerified = true; u.Update(); } ret["FacebookAutoLoginUsrMatch"] = true; return ret; } } #endregion #region if we have a user that matches the email from facebook, we should suggest it, but not log in var user = facebook.GetObject("me", null); string email = user.Value<string>("email"); if (email.Length > 0) { Query qEmail = new Query(); qEmail.QueryCondition = new Q(Usr.Columns.Email, email); UsrSet usEmail = new UsrSet(qEmail); if (usEmail.Count > 0) { ret["FacebookEmailMatch"] = true; ret["FacebookEmailMatchToCurrentUser"] = !usEmail[0].IsSkeleton && usEmail[0].DateTimeLastAccess.AddMonths(2) > DateTime.Now; if (usEmail[0].EnhancedSecurity) ret["EnhancedSecurity"] = true; Hashtable emailMatchUsr = new Hashtable(); emailMatchUsr["NickName"] = usEmail[0].NickName; emailMatchUsr["Email"] = usEmail[0].Email; if (usEmail[0].NickName.Length > 0) emailMatchUsr["Link"] = usEmail[0].Link(); emailMatchUsr["HasNullPassword"] = usEmail[0].HasNullPassword; ret["EmailMatchUsr"] = emailMatchUsr; return ret; } } #endregion return ret; }
public static Hashtable GetHomePlaceFromFacebook() { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); JObject user = facebook.GetObject("me", null); Hashtable ret = new Hashtable(); ret["HomePlace"] = getHomePlaceFromFacebookInternal(user); return ret; }
public static Hashtable CreateNewAccount(Hashtable detailsPanelData) { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); JObject user = facebook.GetObject("me", null); string email = user.Value<string>("email"); string firstName = user.Value<string>("first_name"); string lastName = user.Value<string>("last_name"); Hashtable ret = new Hashtable(); Query qUID = new Query(); qUID.QueryCondition = new Q(Usr.Columns.FacebookUID, facebook.Uid); UsrSet usUID = new UsrSet(qUID); if (usUID.Count == 0) { Usr u = Usr.CreateNewUsrMaster(email, "", firstName, lastName, "", false); u.IsEmailVerified = true; u.IsSkeleton = true; u.NeedsCaptcha = false; u.Update(); try { linkAndLogin(u, ret, facebook, user, detailsPanelData); //this will always run u.Update() } catch (Exception ex) { //maybe we created a duplicate? //try to find usr by facebook id... UsrSet us = new UsrSet(new Query(new Q(Usr.Columns.FacebookUID, facebook.Uid))); if (us.Count > 0) { u = us[0]; loginAndSetAuthCookie(u, ret, facebook.AccessToken); //this will always run u.Update() } else throw ex; } try { u.SendWelcomeEmail(null, null, ""); } catch { } return ret; } else throw new Exception("Can't create new user - already have one."); }
public static Hashtable SwitchAccounts(string currentUIDFromFacebook, int autoLoginUsrK, string autoLoginUsrLoginString, Hashtable detailsPanelData) { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); JObject user = facebook.GetObject("me", null); if (facebook.Uid != long.Parse(currentUIDFromFacebook)) throw new Exception("Inconsistant facebook login"); Usr u = new Usr(autoLoginUsrK); if (u.LoginString.ToLower() == autoLoginUsrLoginString.ToLower()) { Hashtable ret = new Hashtable(); if (checkSkeleton(u, ret, null, detailsPanelData, user)) return ret; UsrSet usOld = new UsrSet(new Query(new Q(Usr.Columns.FacebookUID, facebook.Uid))); foreach (Usr uOld in usOld) { uOld.FacebookUID = null; uOld.FacebookConnected = false; if (!uOld.PassedCaptcha.HasValue || !uOld.PassedCaptcha.Value) uOld.NeedsCaptcha = true; uOld.Update(); } linkAndLogin(u, ret, facebook, user, detailsPanelData); return ret; } else throw new Exception(); }
static void linkAndLogin(Usr u, Hashtable returnValue, FacebookGraphAPI facebook, JObject user, Hashtable detailsPanelData) { if (checkSkeleton(u, returnValue, null, detailsPanelData, user)) return; if (u.IsSkeleton) { getInformationFromFacebook(u, user); } if (detailsPanelData != null) { updateFromDetailsData(u, detailsPanelData); } if (u.FacebookUID != facebook.Uid && u.FacebookStory.HasValue && u.FacebookStory.Value) { FacebookPost.CreateNewConnect(facebook, u.K); } u.FacebookUID = facebook.Uid; u.FacebookConnected = true; u.FacebookConnectedDateTime = DateTime.Now; loginAndSetAuthCookie(u, returnValue, facebook.AccessToken); //this will always run u.Update() }
public static Hashtable LinkAccounts(string nickNameOrEmail, string password, Hashtable detailsPanelData) { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); var user = facebook.GetObject("me", null); string email = user.Value<string>("email"); Hashtable ret = new Hashtable(); if (nickNameOrEmail.Trim().Length == 0) { ret["Error"] = true; return ret; } Q q = null; if (nickNameOrEmail.Contains("@")) q = new Q(Usr.Columns.Email, nickNameOrEmail.Trim()); else q = new Q(Usr.Columns.NickName, nickNameOrEmail.Trim()); UsrSet us = new UsrSet(new Query(q)); if (us.Count == 0) { //throw new Exception("User not found"); ret["Error"] = true; return ret; } Usr u = us[0]; if (!u.CheckPassword(password.Trim())) { //throw new Exception("Wrong password"); ret["Error"] = true; return ret; } linkAndLogin(u, ret, facebook, user, detailsPanelData); return ret; }
public static Hashtable AutoLinkByEmail(Hashtable detailsPanelData) { var facebook = new FacebookGraphAPI(Facebook.Apps.Dsi); Hashtable ret = new Hashtable(); var user = facebook.GetObject("me", null); string email = user.Value<string>("email"); if (email.Length > 0) { Query qEmail = new Query(); qEmail.QueryCondition = new Q(Usr.Columns.Email, email); UsrSet usEmail = new UsrSet(qEmail); if (usEmail.Count > 0 && !usEmail[0].EnhancedSecurity) { ret["FacebookEmailMatch"] = true; linkAndLogin(usEmail[0], ret, facebook, user, detailsPanelData); return ret; } } ret["FacebookEmailMatch"] = false; return ret; }