public bool SendInvitations() { Page.Validate(); if (!Page.IsValid) { return(false); } try { string[] emailAddresses = TextUtil.SplitEmailAddresses(txtEmailAddresses.Text); if (emailAddresses != null) { txtEmailAddresses.Text = ""; // Filter out all invalid emails var validEmails = new List <string>(); var invalidEmails = new List <string>(); var alreadyInvitedEmails = new Dictionary <String, DateTime>(); bool ownEmailSupplied = false; var existingInvites = _memberFriendsQuery.GetFriendInvitations(LoggedInMember.Id); foreach (string email in emailAddresses) { IValidator validator = EmailAddressValidatorFactory.CreateValidator(EmailAddressValidationMode.SingleEmail, false); var errors = validator.IsValid(email) ? null : validator.GetValidationErrors("EmailAddress"); if (errors == null || errors.Length == 0) { if ((String.Compare(LoggedInMember.GetBestEmailAddress().Address, email, true)) == 0) { ownEmailSupplied = true; continue; } var existingInvite = GetInviteForEmail(email, existingInvites); if (existingInvite != null && !_memberFriendsCommand.CanSendInvitation(existingInvite)) { if (existingInvite.LastSentTime == null) { throw new ArgumentNullException("The last sending time was not set, but invite sending was not allowed."); } alreadyInvitedEmails.Add(email, existingInvite.LastSentTime.Value); continue; } validEmails.Add(email); continue; } invalidEmails.Add(email); } // Create a donation request. DonationRequest request = GetDonationRequest(); // Create invitations. var duplicateFriends = SendFriendInvitations(LoggedInMember.Id, validEmails, txtBody.Text, request == null ? (Guid?)null : request.Id); foreach (string duplicateEmail in duplicateFriends) { validEmails.Remove(duplicateEmail); } // Display all errors if (invalidEmails.Count > 0) { string invalidEmailsToReproccess = String.Empty; for (int i = 0; i < invalidEmails.Count; i++) { if (i != 0) { invalidEmailsToReproccess += ","; } invalidEmailsToReproccess += invalidEmails[i]; } txtEmailAddresses.Text = invalidEmailsToReproccess; // Setup the styles to display the mock validator inline txtEmailAddresses.Style.Add("float", "left"); invalidEmailsPanel.Style.Add("float", "left"); invalidEmailsPanel.Style.Add("width", "160px"); invalidEmailsPanel.Style.Add("padding-left", "20px"); // Show the error image and display error text invalidEmailsPanel.Visible = true; } if (duplicateFriends.Count > 0) { alreadyFriendsPanel.Visible = true; var sb = new StringBuilder(); foreach (string email in duplicateFriends) { sb.AppendLine(email + "<br />"); } alreadyFriendsList.InnerHtml = sb.ToString(); } if (alreadyInvitedEmails.Keys.Count > 0) { duplicateInvitesPanel.Visible = true; var sb = new StringBuilder(); foreach (KeyValuePair <String, DateTime> emailAndDatePair in alreadyInvitedEmails) { int resendableDays = Container.Current.Resolve <int>("linkme.domain.roles.networking.invitationResendableDays"); DateTime dateLastSent = emailAndDatePair.Value; int daysBeforeResend = (dateLastSent.AddDays(resendableDays) - DateTime.Now).Days; string whenCanBeResentDescription; if (daysBeforeResend == 0) { whenCanBeResentDescription = String.Format("today at {0}", dateLastSent.ToShortTimeString()); } else if (daysBeforeResend == 1) { whenCanBeResentDescription = "tomorrow"; } else { whenCanBeResentDescription = String.Format("in {0} days", daysBeforeResend); } sb.AppendLine(String.Format("{0} (Can be resent {1}.)<br />", emailAndDatePair.Key, whenCanBeResentDescription)); } duplicateList.InnerHtml = sb.ToString(); } if (ownEmailSupplied) { LinkMePage.AddError(ValidationErrorMessages.INVITE_YOURSELF); } if (validEmails.Count > 0) { if (request != null) { donationWillBeMade.Visible = true; } invitesSentPanel.Visible = true; var sb = new StringBuilder(); foreach (string email in validEmails) { sb.AppendLine(email + "<br />"); } invitesSent.InnerHtml = sb.ToString(); } return(true); } return(false); } catch (DailyLimitException) { LinkMePage.AddError(ValidationErrorMessages.DAILY_LIMIT_EXCEEDED); return(false); } }
protected void Page_Load(object sender, EventArgs e) { int i = 0; while (true) { i++; try { Response.Clear(); ErrorManager.Initialize(Member.Null()); if (Utilities.isMobileBrowser()) { Utilities.MoveToSecure(); } DateTime startTime = DateTime.Now; string HTTP_Protocol = (Request.IsSecureConnection) ? "https://" : "http://"; Uri PageUri = new Uri(HTTP_Protocol + Request.Url.Host + Request.RawUrl); try { SqlConnection = new MySqlConnection("Server=localhost;Uid=root;Pwd=hl1vlAbR9a3Riu;database=blazegameshome5;Pooling=true;Min Pool Size=5;Max Pool Size=60;"); SqlConnection.Open(); } catch (MySql.Data.MySqlClient.MySqlException) { MySqlConnection.ClearAllPools(); SqlConnection = new MySqlConnection("Server=localhost;Uid=root;Pwd=hl1vlAbR9a3Riu;database=blazegameshome5"); SqlConnection.Open(); } #region Build PageEditor If Needed BlazeGames.Web.Core.Page PageEditor = new BlazeGames.Web.Core.Page(1, SqlConnection); if (PageEditor.Code != File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/bin/PageEditor.cs")) { PageEditor.Code = File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/bin/PageEditor.cs"); System.CodeDom.Compiler.CompilerErrorCollection errors = PageEditor.Compile(); if (errors.Count >= 1) { ErrorManager.Error(errors[0].ErrorText); } } #endregion ErrorManager.Initialize(SqlConnection); string NewSessionKey = ""; while (true) { NewSessionKey = Guid.NewGuid().ToString(); MySqlCommand SessionVerifyQuery = new MySqlCommand("SELECT ID FROM members WHERE WebSessionKey=@WebSessionKey", SqlConnection); SessionVerifyQuery.Parameters.AddWithValue("@WebSessionKey", NewSessionKey); MySqlDataReader SessionVerifyReader = SessionVerifyQuery.ExecuteReader(); if (!SessionVerifyReader.Read()) { SessionVerifyReader.Close(); break; } else { SessionVerifyReader.Close(); continue; } } if (Request.Cookies["BlazeGames"] == null) { BGxCookie = new System.Web.HttpCookie("BlazeGames"); BGxCookie.Values.Add("WebSession", NewSessionKey); BGxCookie.Expires = DateTime.Now.AddDays(7); BGxCookie.Domain = ".blaze-games.com"; Response.Cookies.Add(BGxCookie); } else { BGxCookie = Request.Cookies["BlazeGames"]; System.Web.HttpCookie BGxCookieNew = new System.Web.HttpCookie("BlazeGames"); BGxCookieNew.Values.Add("WebSession", BGxCookie.Values["WebSession"]); BGxCookieNew.Expires = DateTime.Now.AddDays(7); BGxCookieNew.Domain = ".blaze-games.com"; Response.Cookies.Add(BGxCookieNew); BGxCookie = BGxCookieNew; } //Response.Write(BGxCookie.Values["WebSession"] + "<br />" + Request.UserHostAddress); //Response.End(); Member LoggedInMember; if (Utilities.GET("Account") != "" && Utilities.GET("Password") != "") { string Account = Utilities.GET("Account"), Password = Utilities.GET("Password"); if (Member.TryLoginWithPassword(Account, Password, SqlConnection)) { LoggedInMember = new Member(Account, SqlConnection); } else { LoggedInMember = new Member(BGxCookie.Values["WebSession"], Request.UserHostAddress, SqlConnection); } } else { LoggedInMember = new Member(BGxCookie.Values["WebSession"], Request.UserHostAddress, SqlConnection); } if (Utilities.POST("Account") != "" && Utilities.POST("Password") != "" && Utilities.POST("Act") == "Login" && !LoggedInMember.IsValid) { if (!Member.Login(Utilities.POST("Account"), Utilities.POST("Password"), BGxCookie.Values.Get("WebSession"), Request.UserHostAddress, SqlConnection)) { ErrorManager.Fatal("Login Failed!\r\n<a href='" + PageUri.AbsolutePath + "'>Go Back</a><script>setTimeout('location.href = \"" + PageUri.AbsolutePath + "\";', 2500);</script>", "Account: " + Utilities.POST("Account") + "<br />Hash: " + Member.HashPassword(Utilities.POST("Password"))); } else { LoggedInMember.Load(); ErrorManager.Initialize(LoggedInMember); ErrorManager.Message("Login Complete!\r\n<a href='" + PageUri.AbsolutePath + "'>Continue</a><script>setTimeout('location.href = \"" + PageUri.AbsolutePath + "\";', 2500);</script>"); } } else if (Utilities.GET("Act") == "Logout") { BGxCookie = new System.Web.HttpCookie("BlazeGames"); BGxCookie.Values.Add("WebSession", Guid.NewGuid().ToString()); BGxCookie.Domain = ".blaze-games.com"; BGxCookie.Expires = DateTime.Now.AddMonths(1); Response.Cookies.Add(BGxCookie); ErrorManager.Initialize(new Member("", "", SqlConnection)); ErrorManager.Message("Logout Complete!\r\n<a href='" + PageUri.AbsolutePath + "'>Go Back</a><script>setTimeout('location.href = \"" + PageUri.AbsolutePath + "\";', 2500);</script>"); } LoggedInMember.Load(); ErrorManager.Initialize(LoggedInMember); Logging Log = new Logging(SqlConnection, LoggedInMember); HttpHeader HttpHead = new HttpHeader(); Core.Events Event = new Core.Events(); PageSys = new DynamicPages(PageUri.AbsolutePath, SqlConnection, LoggedInMember, Log, HttpHead, Event); PageSys.onPageInitialize(); PageSys.onPageLoad(); string Buffer = ""; if (Utilities.isMobileApps()) { Buffer = File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/MobileApps/index.txt"); } else if (Utilities.isMobileBrowser()) { Buffer = File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/Mobile/index.txt"); } else { Buffer = File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/" + HttpHead.Theme + "/index.txt"); } Buffer = Buffer.Replace("<!--{PageHeader}-->", HttpHead.ToString() + "\r\n<style type='text/css'>\r\n" + PageSys.CurrentPage.PageCSS + "\r\n</style>\r\n" + "<script type='text/javascript'>\r\n" + PageSys.CurrentPage.PageJS + "\r\n</script>"); Buffer = Buffer.Replace("<!--{PageContents}-->", PageSys.CurrentPage.PageHTML); Buffer = Buffer.Replace("<!--{PageCode}-->", PageSys.onPageReturn()); Buffer = Buffer.Replace("<!--{WIDGET_Clock}-->", File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/Default/Widgets/Clock.txt")); if (LoggedInMember.IsValid) { Buffer = Buffer.Replace("<!--{WIDGET_Login}-->", File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/Default/Widgets/Login_Member.txt")); } else { Buffer = Buffer.Replace("<!--{WIDGET_Login}-->", File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/Default/Widgets/Login_Guest.txt")); } Buffer = Buffer.Replace("<!--{WIDGET_Social)-->", File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/Default/Widgets/Social.txt")); Buffer = Buffer.Replace("<!--{WIDGET_Posts}-->", File.ReadAllText(HttpContext.Current.Server.MapPath(".") + "/Themes/Default/Widgets/Posts.txt")); Buffer = Buffer.Replace("<!--{Time}-->", Utilities.GetDateTime()); Buffer = Buffer.Replace("<!--{Nickname}-->", LoggedInMember.Nickname); Buffer = Buffer.Replace("<!--{ProfileImage}-->", LoggedInMember.GetProfileImage()); Buffer = Buffer.Replace("<!--{Url_Secure)-->", Utilities.GetCurrentUrl(true)); Buffer = Buffer.Replace("<!--{PageName}-->", PageSys.PageURL); foreach (string ParamKey in HttpHead.ThemeParameters.Keys) { Buffer = Buffer.Replace("{" + ParamKey + "}", HttpHead.ThemeParameters[ParamKey]); } Buffer = Buffer.Replace("{ThemePath}", "/Themes/" + HttpHead.Theme + "/"); DateTime stopTime = DateTime.Now; TimeSpan duration = stopTime - startTime; SqlConnection.CancelQuery(100); SqlConnection.Close(); //SqlConnection.Dispose(); Response.Write(@"<!-- ------------------------------------------ ---- Blaze Games Web v5 Debug Console ---- ------------------------------------------ Script Execution Time: " + duration.Milliseconds + @"MS sqlConnection State: " + SqlConnection.State + @" --> "); Response.Write(Buffer); Response.Flush(); Response.End(); PageSys.onPageUnLoad(); break; } catch (Exception ex) { if (i == 5) { throw ex; } continue; } } }
private void InitialiseInvitations() { var friendInvitations = _memberFriendsQuery.GetFriendInvitations(LoggedInMember.Id, LoggedInMember.GetBestEmailAddress().Address); var representativeInvitations = _memberFriendsQuery.GetRepresentativeInvitations(LoggedInMember.Id, LoggedInMember.GetBestEmailAddress().Address); var allIds = (from i in friendInvitations select i.InviterId) .Concat(from i in representativeInvitations select i.InviterId); _views = _memberViewsQuery.GetPersonalViews(LoggedInUserId, allIds); if (friendInvitations.Count > 0) { rptInvitations.Visible = true; rptInvitations.DataSource = friendInvitations; rptInvitations.DataBind(); } else { rptInvitations.Visible = false; litNoInvitationsMessage.Visible = true; litNoInvitationsMessage.Text = NoPendingInvitations; } if (representativeInvitations.Count > 0) { phRepresentative.Visible = true; rptRepresentativeInvitations.DataSource = representativeInvitations; rptRepresentativeInvitations.DataBind(); } else { phRepresentative.Visible = false; } }
public AjaxResult SaveContactDetails(string homePhone, string workPhone, string mobilePhone, string emailAddress) { try { EnsureMemberLoggedIn(); var errors = new List <string>(); if (string.IsNullOrEmpty(homePhone) && string.IsNullOrEmpty(workPhone) && string.IsNullOrEmpty(mobilePhone)) { errors.Add(ValidationErrorMessages.REQUIRED_AT_LEAST_ONE_PHONE_NUMBER); } ValidatePhoneNumber(homePhone, errors); ValidatePhoneNumber(workPhone, errors); ValidatePhoneNumber(mobilePhone, errors); if (string.IsNullOrEmpty(emailAddress)) { errors.Add(ValidationErrorMessages.REQUIRED_FIELD_EMAIL_ADDRESS); } else { IValidator validator = EmailAddressValidatorFactory.CreateValidator(EmailAddressValidationMode.SingleEmail, false); var validationErrors = validator.IsValid(emailAddress) ? null : validator.GetValidationErrors("EmailAddress"); if (validationErrors != null && validationErrors.Length > 0) { errors.Add(((IErrorHandler) new StandardErrorHandler()).FormatErrorMessage(validationErrors[0])); } } if (errors.Count > 0) { return(new AjaxResult(AjaxResultCode.FAILURE, errors.ToArray())); } // Check the email. var emailChanged = string.Compare(LoggedInMember.GetBestEmailAddress().Address, emailAddress, StringComparison.InvariantCultureIgnoreCase) != 0; if (emailChanged) { // Check that the email address is not being used by someone else. var user = _membersQuery.GetMember(emailAddress); if (user != null && user.Id != LoggedInMember.Id) { return(new AjaxResult(AjaxResultCode.FAILURE, ValidationErrorMessages.DUPLICATE_USER_PROFILE)); } } // Update. var member = LoggedInMember; member.EmailAddresses = new List <EmailAddress> { new EmailAddress { Address = emailAddress } }; member.PhoneNumbers = new List <PhoneNumber>(); if (!string.IsNullOrEmpty(mobilePhone)) { member.PhoneNumbers.Add(new PhoneNumber { Number = mobilePhone, Type = PhoneNumberType.Mobile }); } if (!string.IsNullOrEmpty(homePhone)) { member.PhoneNumbers.Add(new PhoneNumber { Number = homePhone, Type = PhoneNumberType.Home }); } if (!string.IsNullOrEmpty(workPhone)) { member.PhoneNumbers.Add(new PhoneNumber { Number = workPhone, Type = PhoneNumberType.Work }); } _memberAccountsCommand.UpdateMember(member); return(new AjaxResult(AjaxResultCode.SUCCESS)); } catch (Exception ex) { return(HandleException(ex)); } }