public void TestThatNamespaceCacheKeysAreInvalidatedBySqlCommands()
		{
			Caching.Instances.Main.FlushAll();
			Usr u1 = new Usr()
			{
				NickName= Guid.NewGuid().ToString(),
				Email = Guid.NewGuid().ToString()
			};
			u1.Update();
			Usr u2 = new Usr()
			{
				NickName = Guid.NewGuid().ToString(),
				Email = Guid.NewGuid().ToString()
			};
			u1.Update();
			u2.Update();
			Assert.IsNull(Caching.Instances.Main.Get(Caching.CacheKeys.Usr.Banners(u1.K)));
			Assert.IsNull(Caching.Instances.Main.Get(Caching.CacheKeys.Usr.Banners(u2.K)));
			Banner b = new Banner() { UsrK = u1.K };
			b.Update();
			Assert.IsNotNull(Caching.Instances.Main.Get(Caching.CacheKeys.Usr.Banners(u1.K)));
			Assert.IsNull(Caching.Instances.Main.Get(Caching.CacheKeys.Usr.Banners(u2.K)));
			
			b.UsrK= u2.K;
			b.Update();
			Assert.IsNotNull(Caching.Instances.Main.Get(Caching.CacheKeys.Usr.Banners(u1.K)));
			Assert.IsNotNull(Caching.Instances.Main.Get(Caching.CacheKeys.Usr.Banners(u2.K)));
			
			
		}
Example #2
0
		public void TestDeletesRemoveBobsFromCache()
		{
			Usr usr = new Usr();
			usr.Update();
			UsrTableDef def = new UsrTableDef();
			Caching.Instances.Main.Set(new Caching.CacheKeys.BobCacheKey("Usr", usr.K, def.TableCacheKey), Guid.NewGuid().ToString());
			Assert.IsNotNull(Caching.Instances.Main.Get(new Caching.CacheKeys.BobCacheKey("Usr", usr.K, def.TableCacheKey)));
			usr.Delete();
			Assert.IsNull(Caching.Instances.Main.Get(new Caching.CacheKeys.BobCacheKey("Usr", usr.K, def.TableCacheKey)));
		}
Example #3
0
		public void Delete_RemoveUsr1ThenLoadUsr1_BobNotFoundThrown()
		{
			SetupCacheForTesting();

			Usr usr = new Usr();
			usr.Update();
			int k = usr.K;
			usr.Delete();

			usr = new Usr(k);
		}
Example #4
0
		public void CountUsrs_PlaceConditions_NotIncludingIfUsrHasBeenToEventInTown()
		{
			new Delete(TablesEnum.Usr, new Q(true)).Run();

			Random r = new Random();
			List<int> placeKs = new List<int>() { 1, 2, 3, 4 };
			List<int> notPlaceKs = new List<int>() { 5, 6, 7, 8, 9, 10, 11 };

			int usrsToCreate = 15;
			int usrs = 0;
			usrsToCreate.Times(() =>
			{
				Usr u = new Usr()
				{
					Email = Guid.NewGuid().ToString(),
					IsSkeleton = false,
					IsEmailVerified = true,
					SendFlyers = true
				};
				u.Update();

				int i = r.Next(placeKs.Count + notPlaceKs.Count);
				int placeK;
				if (i < placeKs.Count)
				{
					usrs++;
					placeK = placeKs[i];
				}
				else
				{
					placeK = notPlaceKs[i - placeKs.Count];
				}
				UsrPlaceVisit up = new UsrPlaceVisit()
				{
					UsrK = u.K,
					PlaceK = placeK
				};
				up.Update();
			});

			Assert.AreEqual(usrs, Flyer.CountUsrs(placeKs, new List<int>(), false));
		}
Example #5
0
		public void BobsCachingIsWorking()
		{
			SetupCacheForTesting();
			
			UnitTestUtilities.Sql.SqlTrace trace = new UnitTestUtilities.Sql.SqlTrace(Common.Properties.ConnectionString);
			trace.Start();
			Usr usr = new Usr();
			usr.Update();
			trace.Stop();
			Assert.AreNotEqual(0, trace.TotalReads, "First read was zero");
			trace.ClearData();
			trace.Start();
			Usr selectedUsr = new Usr(usr.K);
			trace.Stop();
			Assert.AreNotEqual(0, trace.TotalReads, "Second read was zero");

			trace.ClearData();
			trace.Start();
			Usr cachedUsr = new Usr(usr.K);
			trace.Stop();
			Assert.AreEqual(0, trace.TotalReads, "Third read was not zero");
		}
Example #6
0
		public void CountUsrs_NoConditions()
		{
			new Delete(TablesEnum.Usr, new Q(true)).Run();
			int usrsToCreate = 15;
			usrsToCreate.Times(() =>
			{
				Usr u = new Usr()
				{
					Email = Guid.NewGuid().ToString(),
					IsSkeleton = false,
					IsEmailVerified = true,
					SendFlyers = true
				};
				u.Update();
			});

			Query q = new Query();
			q.QueryCondition = new And(new Q(Usr.Columns.IsSkeleton, false), new Q(Usr.Columns.SendFlyers, true));
			q.ReturnCountOnly = true;

			int totalUsrs = new UsrSet(q).Count;
			Assert.AreEqual(usrsToCreate, totalUsrs);
			Assert.AreEqual(totalUsrs, Flyer.CountUsrs(new List<int>(), new List<int>(), false));
		}
Example #7
0
		public void Test()
		{
			BuddyImporterService service = new BuddyImporterService();
			string email = "*****@*****.**";

			Usr u = new Usr();
			u.Update();

			Usr u2 = new Usr()
			{
				Email = email
			};
			u2.Update();

			Buddy b = new Buddy()
			{
				UsrK = u.K,
				BuddyUsrK = u2.K
			};
			b.Update();

			List<Contact> cList;
			List<Usr> uList;

			List<Contact> list = new List<Contact>()
			{
				new Contact("Bob", email)
			};

			int alreadyBuddies;
			service.SplitOutEmailContacts(list, u.K, out alreadyBuddies, out uList, out cList);

			Assert.AreEqual(1, uList.Count);
			Assert.IsTrue((bool)uList[0].ExtraSelectElements["BuddyRequested"]);
			Assert.AreEqual(0, cList.Count);
		}
Example #8
0
		public bool ProcessLoginPart(ref int currentIndex, string[] urlParts)
		{
			if (urlParts[currentIndex].StartsWith("login") || urlParts[currentIndex].StartsWith("logout"))
			{
				try
				{
					LoginPartLogOutFirst = urlParts[currentIndex].StartsWith("logout"); // logout is used when forcing a log out (e.g. when admin or mod is needed)

					if (urlParts[currentIndex].Contains('-'))
					{
						string[] loginArr = urlParts[currentIndex].Split('-');
						LoginPartUsrK = loginArr.Length >= 2 ? int.Parse(loginArr[1]) : 0;
						LoginPartLoginString = loginArr.Length >= 3 ? loginArr[2] : "";
					}

					currentIndex++;

					#region construct LoggedInPlainUrl
					string redirectUrl = "";
					for (int part = currentIndex; part < urlParts.Length; part++)
						redirectUrl += "/" + urlParts[part];

					if (redirectUrl.Length == 0)
						LoggedInPlainUrl = "/";
					else
						LoggedInPlainUrl = redirectUrl;

					if (HttpContext.Current.Request.QueryString.ToString().Length > 0)
						LoggedInPlainUrl += "?" + HttpContext.Current.Request.QueryString.ToString();
					#endregion

					Usr u = null;
					try
					{
						u = new Usr(LoginPartUsrK);
						if (u.LoginString.ToLower().Equals(LoginPartLoginString.ToLower()))
						{
							if (!u.IsEmailVerified)
							{
								u.IsEmailVerified = true;
								u.Update();
							}
						}
					}
					catch { }

					if (Usr.Current == null || (LoginPartUsrK > 0 && Usr.Current.K != LoginPartUsrK))
					{
						if (u.LoginString.ToLower().Equals(LoginPartLoginString.ToLower()))
						{
							LoginPartUsrEmail = u.Email;
							LoginPartUsrIsSkeleton = u.IsSkeleton;
							LoginPartUsrIsFacebookNotConfirmed = !u.FacebookStory.HasValue;
							LoginPartUsrIsEnhancedSecurity = u.EnhancedSecurity && (Usr.Current == null || !Usr.Current.IsAdmin);
							LoginPartUsrNeedsCaptcha = u.NeedsCaptcha.HasValue && u.NeedsCaptcha.Value && Settings.CaptchaEnabledStatus == Settings.CaptchaEnabledStatusOption.On;
							LoginPartUsrHomePlaceK = u.HomePlaceK;
							LoginPartUsrFavouriteMusicK = u.FavouriteMusicTypeK;
							LoginPartUsrSendSpottedEmails = u.SendSpottedEmails;
							LoginPartUsrSendEflyers = u.SendFlyers;

							if (LoginPartUsrNeedsCaptcha)
							{
								string text = Cambro.Misc.Utility.GenRandomChars(5).ToUpper() + "|" + HttpUtility.UrlEncode(u.Email.ToLower());
								LoginPartUsrCaptchaEncrypted = Cambro.Misc.Utility.Encrypt(text, DateTime.Now.AddHours(1));
							}

							if (LoginPartUsrIsSkeleton || LoginPartUsrIsEnhancedSecurity || LoginPartUsrNeedsCaptcha)
							{
								PageType = PageTypes.Pages;
								PageName = "AutoLogin";
								return true;
							}
							else
							{
								u.LogInAsThisUserNew();
								if (!DisableAllActions)
								{
									if (u.EmailHold)
										HttpContext.Current.Response.Redirect("/popup/unsubscribe");
									else
										HttpContext.Current.Response.Redirect(LoggedInPlainUrl);
								}
							}
						}
						else
						{
							LoginFailed = true;

							PageType = PageTypes.Pages;
							PageName = "AutoLogin";
							return true;
						}

					}
					else if (LoginPartLogOutFirst)
					{
						PageType = PageTypes.Pages;
						PageName = "AutoLogin";
						return true;
					}
					else
					{
						if (!DisableAllActions)
							HttpContext.Current.Response.Redirect(LoggedInPlainUrl);
					}


					//if (Usr.Current != null && (LoginPartUsrK == 0 || Usr.Current.K == LoginPartUsrK) && LoginPartLogin)
					//{
					//    if (!DisableAllActions)
					//    {
					//        if (!Usr.Current.IsEmailVerified &&
					//            LoginPartUsrK > 0 &&
					//            LoginPartLoginString.Length > 0 &&
					//            Usr.Current.LoginString.ToLower() == LoginPartLoginString.ToLower())
					//        {
					//            Usr.Current.IsEmailVerified = true;
					//            Usr.Current.Update();
					//            Usr.Current = null;
					//        }
						
					//        if (Usr.Current.EmailHold)
					//            HttpContext.Current.Response.Redirect("/popup/unsubscribe");
					//        else
					//            HttpContext.Current.Response.Redirect(LoggedInPlainUrl);

					//    }
					//    return false;
					//}
					//else
					//{
					//    PageType = PageTypes.Pages;
					//    PageName = "AutoLogin";
					//    return true;
					//}
				}
				catch
				{
					PageType = PageTypes.Pages;
					PageName = "AutoLogin";
					return true;
				}
			}
			return false;
		}
Example #9
0
		public void CountUsrs_MusicConditions_QueryIncludingAllMusic_GetsAllUsrs()
		{
			new Delete(TablesEnum.Usr, new Q(true)).Run();

			Random r = new Random();
			List<int> musicTypeKs = new List<int>() { 1, 2, 3, 4 };

			int usrsToCreate = 15;
			usrsToCreate.Times(() =>
			{
				Usr u = new Usr()
				{
					Email = Guid.NewGuid().ToString(),
					IsSkeleton = false,
					IsEmailVerified = true,
					SendFlyers = true
				};
				u.Update();

				int i = r.Next(musicTypeKs.Count * 2);
				if (i < musicTypeKs.Count)
				{
					UsrMusicTypeFavourite um = new UsrMusicTypeFavourite()
					{
						UsrK = u.K,
						MusicTypeK = musicTypeKs[i]
					};
					um.Update();
				}
			});

			Assert.AreEqual(usrsToCreate, Flyer.CountUsrs(new List<int>(), musicTypeKs, false));
		}
Example #10
0
		private void ProcessDonation()
		{
			if (!this.Enabled)
			{
				this.Enabled = true;
				this.BuyDateTime = DateTime.Now;
				this.Update();
			}

			var u = new Usr(this.UsrK);
			u.RolloverDonationIconK = this.DonationIconK;
			u.Update();
		}
Example #11
0
		private void CreateUsr(int musicTypeK, int homePlaceK, int eventPlaceK, int visitPlaceK, bool isPromoter)
		{
			Usr u = new Usr()
			{
				Email = Guid.NewGuid().ToString(),
				IsSkeleton = false,
				IsEmailVerified = true,
				SendFlyers = true,
				HomePlaceK = homePlaceK,
				IsPromoter = isPromoter
			};
			u.Update();

			UsrMusicTypeFavourite um = new UsrMusicTypeFavourite()
			{
				UsrK = u.K,
				MusicTypeK = musicTypeK
			};
			um.Update();



			Venue v = new Venue()
			{
				PlaceK = eventPlaceK
			};
			v.Update();

			Event e = new Event()
			{
				VenueK = v.K
			};
			e.Update();

			UsrEventAttended ue = new UsrEventAttended()
			{
				UsrK = u.K,
				EventK = e.K
			};
			ue.Update();


			UsrPlaceVisit up = new UsrPlaceVisit()
			{
				UsrK = u.K,
				PlaceK = visitPlaceK
			};
			up.Update();
		}
Example #12
0
		private static Usr CreateSkeletonUserAndSendWelcomeEmail(Usr invitingUsr, string email, string nickName, Group invitingGroup, string inviteMessage, bool invitedViaContactImporter)
		{
			Usr u = new Usr();
			Random r = new Random();

			u.DateTimeSignUp = DateTime.Now;
			u.DateTimeLastAccess = DateTime.Now;
			u.DateTimeLastPageRequest = DateTime.Now;

			u.IsSkeleton = true;
			u.Email = Cambro.Web.Helpers.StripHtml(email);
			u.EmailDateTime = DateTime.Now;
			if (HttpContext.Current != null)
				u.EmailIp = Utilities.TruncateIp(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]);
			u.LoginString = Cambro.Misc.Utility.GenRandomText(6, r);
			u.RandomNumber = r.NextDouble();
			u.IsAdmin = false;
			u.LoginCount = 0;
			u.FirstName = "";
			u.LastName = "";

			u.NickName = Cambro.Web.Helpers.StripHtml(nickName);
			u.Mobile = "";
			u.AddressPostcode = "";

			u.SendSpottedEmails = true;
			u.UpdateLargeEvents = 5000;
			u.UpdateSendBuddies = false;
			u.UpdateSendGenericMusic = false;
			u.SendSpottedTexts = true;
			u.SendFlyers = true;
			u.SendInvites = true;
			u.SendPartnerEmails = false;
			u.SendPartnerTexts = false;
			u.IsEmailVerified = true;

			if (invitingUsr != null)
				u.AddedByUsrK = invitingUsr.K;

			if (invitingGroup != null)
				u.AddedByGroupK = invitingGroup.K;

			u.InvitedViaContactImporter = invitedViaContactImporter;

			u.Update();
			
			u.SendWelcomeEmail(invitingUsr, invitingGroup, inviteMessage);

			u = new Usr(u.K);
			return u;

		}
Example #13
0
		//public static bool GetCompliantUniqueNickName(string inNickName, out string outNickName)
		//{
		//    outNickName = inNickName;

		//    int index;
		//    // if it's an email address, remove domain
		//    if (index = outNickName.IndexOf("@") > 0)
		//    {
		//        outNickName = outNickName.Substring(0, outNickName.IndexOf(index));
		//    }

		//    outNickName = Usr.GetCompliantNickName(outNickName);
		//    if (!Usr.NickNameRegex.IsMatch(outNickName))
		//        return false;

		//    else
		//    {
		//        Query q = new Query();
		//        q.QueryCondition = new Q(Usr.Columns.NickName, outNickName);
		//        q.ReturnCountOnly = true;
		//        UsrSet us = new UsrSet(q);
		//        us.Count == 0;
		//    }
		//}
		#endregion

		#region CreateNewUsr
		//public static Usr CreateNewUsr(string email, string password)
		//{
		//    return CreateNewUsr(email, password, "", "");
		//}
		//public static Usr CreateNewUsr(string email, string password, string firstName, string lastName)
		//{
		//    return CreateNewUsr(email, password, firstName, lastName, "");
		//}
		//public static Usr CreateNewUsr(string email, string password, string firstName, string lastName, string emailIp)
		//{
		//    return CreateNewUsr(email, password, firstName, lastName, emailIp, true);
		//}
		public static Usr CreateNewUsrMaster(string email, string password, string firstName, string lastName, string emailIp, bool runUpdate)
		{
			Usr u = new Usr();
			Random r = new Random();

			#region Add data from form

			u.DateTimeSignUp = Time.Now;
			u.DateTimeLastAccess = Time.Now;
			u.DateTimeLastPageRequest = Time.Now;

			u.Email = email.Trim();
			u.EmailDateTime = Time.Now;
			u.EmailIp = emailIp;
			if (password.Trim().Length > 0)
				u.SetPassword(password.Trim(), false);
			u.LoginString = Cambro.Misc.Utility.GenRandomText(6, r);
			u.RandomNumber = r.NextDouble();
			u.IsEmailVerified = false;
			u.IsAdmin = false;
			u.LoginCount = 0;
			u.FirstName = firstName;
			u.LastName = lastName;
			u.NickName = "";
			u.IsSkeleton = true;

			u.SendSpottedEmails = true;
			u.UpdateLargeEvents = 5000;
			u.UpdateSendBuddies = false;
			u.UpdateSendGenericMusic = true;
			u.SendSpottedTexts = true;
			u.SendFlyers = true;
			u.SendInvites = true;
			u.SendPartnerEmails = false;
			u.SendPartnerTexts = false;

			#endregion

			if (runUpdate)
				u.Update();

			return u;
		}
Example #14
0
		public void CountUsrs_PlaceConditions_IncludingIfUsrHasBeenToEventInTown()
		{
			new Delete(TablesEnum.Usr, new Q(true)).Run();

			Random r = new Random();
			List<int> placeKs = new List<int>() { 1, 2, 3, 4 };

			Venue v = new Venue()
			{
				PlaceK = placeKs[0]
			};
			v.Update();

			Event e = new Event()
			{
				VenueK = v.K
			};
			e.Update();

			int usrsToCreate = 15;
			int usrs = 0;
			usrsToCreate.Times(() =>
			{
				Usr u = new Usr()
				{
					Email = Guid.NewGuid().ToString(),
					IsSkeleton = false,
					IsEmailVerified = true,
					SendFlyers = true
				};
				u.Update();

				int i = r.Next(placeKs.Count * 2);
				if (i < placeKs.Count)
				{
					UsrEventAttended ue = new UsrEventAttended()
					{
						UsrK = u.K,
						EventK = e.K
					};
					ue.Update();
					usrs++;
				}
			});

			Assert.AreEqual(usrs, Flyer.CountUsrs(placeKs, new List<int>(), false));
		}
Example #15
0
		public static void CreateLol(Comment comment)
		{
			LolSet ls = new LolSet(
				new Query(
					new And(
						new Q(Lol.Columns.CommentK,comment.K),
						new Q(Lol.Columns.UsrK,Usr.Current.K)
					)
				)
			);
			if (ls.Count==0)
			{
				Usr usr = new Usr(comment.UsrK);
				LolSet lolUniqueSet = new LolSet(new Query(new And(
					new Q(Lol.Columns.CommentUsrK,usr.K),
					new Q(Lol.Columns.UsrK,Usr.Current.K))));
				if (lolUniqueSet.Count==0)
					usr.UniqueMadeLol++;
				usr.TotalMadeLol++;
				usr.Update();

				comment.LolCount++;
				comment.Update();

				Lol l = new Lol();
				l.DateTime=DateTime.Now;
				l.CommentK=comment.K;
				l.UsrK=Usr.Current.K;
				l.CommentUsrK=comment.UsrK;
				l.Update();
				l = new Lol(l.K);
				
				//DateTime lastLolDateTime = Usr.Current.LastLol;
						
				Usr.Current.TotalLol++;
				Usr.Current.LastLol = l.DateTime;
				Usr.Current.Update();

				Comment fullComment = new Comment(comment.K);

				if (!fullComment.Thread.Private && !fullComment.Thread.GroupPrivate && !fullComment.Thread.PrivateGroup)
				{

					if (Usr.Current.FacebookConnected && Usr.Current.FacebookStoryLaugh)
					{
						FacebookPost.CreateLaugh(Usr.Current, comment);
					}

					////LaughStub randomChatLaughStub = getLaughStub(ItemType.LaughAlert, new Chat.RoomSpec(RoomType.Laughs).Guid, fullComment);
					//LaughStub randomChatLaughStub = getLaughStub(ItemType.LaughAlert, new Chat.RoomSpec(RoomType.PublicStream).Guid, fullComment);
					//Chat.SendJsonChatItem(randomChatLaughStub);

					LaughStub randomChatLaughStub1 = getLaughStub(ItemType.LaughAlert, new Chat.RoomSpec(RoomType.PublicStream).Guid, fullComment);
					Chat.SendJsonChatItem(randomChatLaughStub1);
				}
				else
				{
					//LaughStub laughStub = getLaughStub(ItemType.LaughAlert, new Chat.RoomSpec(RoomType.Normal, Model.Entities.ObjectType.Thread, fullComment.ThreadK).Guid, fullComment);
					//UsrSet us = Thread.GetAllLoggedInParticipants(fullComment.Thread);
					//Chat.SendJsonChatItem(laughStub, us);
				}

			}
		}
Example #16
0
		public void CountUsrs_MusicConditions_TestChildImpliesParentMusicType()
		{
			new Delete(TablesEnum.Usr, new Q(true)).Run();

			// 4 is parent of 5
			List<int> musicTypeKs = new List<int>() { 5 };

			Usr u = new Usr()
			{
				Email = Guid.NewGuid().ToString(),
				IsSkeleton = false,
				IsEmailVerified = true,
				SendFlyers = true
			};
			u.Update();

			UsrMusicTypeFavourite um = new UsrMusicTypeFavourite()
			{
				UsrK = u.K,
				MusicTypeK = 4
			};
			um.Update();

			Assert.AreEqual(1, Flyer.CountUsrs(new List<int>(), musicTypeKs, false));
		}
Example #17
0
		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;

		}
Example #18
0
		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;
			
		}
Example #19
0
		static void updateFromDetailsData(Usr u, Hashtable detailsPanelData)
		{

			Place p = new Place((int)detailsPanelData["PlaceK"]);
			u.HomePlaceK = p.K;
			u.AddressCountryK = p.CountryK;

			MusicType mt = new MusicType((int)detailsPanelData["MusicTypeK"]);
			u.FavouriteMusicTypeK = mt.K;

			#region update UsrMusicTypeFavourite table
			try
			{
				UsrMusicTypeFavourite umf = new UsrMusicTypeFavourite();
				umf.UsrK = u.K;
				umf.MusicTypeK = mt.K;
				umf.Update();

				u.UpdateMusicTypesFavouriteCount(false);
			}
			catch { }
			#endregion

			#region update UsrPlaceVisit table
			try
			{
				UsrPlaceVisit upv = new UsrPlaceVisit();
				upv.UsrK = u.K;
				upv.PlaceK = p.K;
				upv.Update();

				u.UpdatePlacesVisitCount(false);
			}
			catch { }
			#endregion

			#region Facebook
			u.FacebookStory = (bool)detailsPanelData["Facebook"];
			u.FacebookStory1 = (bool)detailsPanelData["Facebook"];

			u.FacebookEventAdd = (bool)detailsPanelData["Facebook"];
			u.FacebookEventAttend = (bool)detailsPanelData["Facebook"];

			u.FacebookStoryAttendEvent = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryBuyTicket = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryEventReview = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryFavourite = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryJoinGroup = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryLaugh = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryNewBuddy = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryNewTopic = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryPhotoFeatured = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryPostNews = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryPublishArticle = (bool)detailsPanelData["Facebook"];
			u.FacebookStorySpotted = (bool)detailsPanelData["Facebook"];
			u.FacebookStoryUploadPhoto = (bool)detailsPanelData["Facebook"];

			#endregion

			#region WeeklyEmail
			u.SendSpottedEmails = (bool)detailsPanelData["WeeklyEmail"];
			#endregion

			#region PartyInvites
			u.SendSpottedTexts = (bool)detailsPanelData["PartyInvites"];
			u.SendFlyers = (bool)detailsPanelData["PartyInvites"];
			u.SendInvites = (bool)detailsPanelData["PartyInvites"];
			#endregion

			u.AgreeTerms = true;
			u.LegalTermsUser2 = true;
			u.IsSkeleton = false;
			u.Update();

			#region update Prefs

			if (mt.K != 1)
				Prefs.Current["MusicPref"] = mt.K;

			if (p.CountryK != 224)
				Prefs.Current["HomeCountryK"] = p.CountryK;

			if (mt.K != 1 || p.CountryK != 224)
				Prefs.Current.Update();

			#endregion
		}
Example #20
0
		static void loginAndSetAuthCookie(Usr u, Hashtable returnValue, string facebookAccessToken)
		{
			//normal login stuff
			u.LoginCount++;
			u.DateTimeLastAccess = DateTime.Now;
			if (facebookAccessToken.Length > 0)
				u.FacebookAccessToken = facebookAccessToken;
			u.Update();
			u.LogInAsThisUserDontSetCookieNew();
			

			Hashtable authUsr = new Hashtable();
			authUsr["NickName"] = u.NickName;
			if (u.NickName.Length > 0)
				authUsr["Link"] = u.Link();
			authUsr["Email"] = u.Email;
			authUsr["HasNullPassword"] = u.HasNullPassword;
			returnValue["AuthUsr"] = authUsr;

			returnValue["AuthCookie"] = getAuthCookie(u.GetAuthCookie(), u.K);

		}