private void LoadSettings() { subscriptionGuid = WebUtils.ParseGuidFromQueryString("s", subscriptionGuid); if (subscriptionGuid != Guid.Empty) { subscription = subscriptions.Fetch(subscriptionGuid); if ((subscription != null) && (subscription.SiteGuid == siteSettings.SiteGuid)) { subscriptions.Verify(subscription.SubscribeGuid, true, Guid.Empty); if (subscription.UserGuid == Guid.Empty) { SiteUser user = SiteUser.GetByEmail(siteSettings, subscription.EmailAddress); if (user != null) { subscription.UserGuid = user.UserGuid; subscriptions.Save(subscription); } } LetterInfo.UpdateSubscriberCount(subscription.LetterInfoGuid); } else { subscription = null; } } }
void grdSubscribers_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { string strG = e.CommandArgument.ToString(); switch (e.CommandName) { case "DeleteSubscriber": if (strG.Length == 36) { Guid subscriptionGuid = new Guid(strG); LetterSubscriber s = subscriptions.Fetch(subscriptionGuid); if (s != null) { subscriptions.Delete(s); } LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); WebUtils.SetupRedirect(this, Request.RawUrl); } break; case "SendVerification": if (strG.Length == 36) { Guid subscriptionGuid = new Guid(strG); LetterSubscriber s = subscriptions.Fetch(subscriptionGuid); LetterInfo letterInfo = new LetterInfo(letterInfoGuid); NewsletterHelper.SendSubscriberVerificationEmail( SiteRoot, s.EmailAddress, s.SubscribeGuid, letterInfo, siteSettings); } WebUtils.SetupRedirect(this, Request.RawUrl); break; } }
private void DoUnsubscribe() { if (subscriptionGuid != Guid.Empty) { LetterSubscriber s = subscriptions.Fetch(subscriptionGuid); if (s == null) { ShowNotFoundMessge(); return; } subscriptions.Delete(s); LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); lblUnsubscribe.Text = Resource.NewsletterUnsubscribeSuccess; btnUnsubscribeConfirm.Visible = false; lblUnsubscribe.Visible = true; return; } LetterInfo letterInfo = new LetterInfo(letterInfoGuid); if (letterInfo.LetterInfoGuid == Guid.Empty) { ShowNotFoundMessge(); return; } List <LetterSubscriber> userSubscriptions = subscriptions.GetListByUser(siteSettings.SiteGuid, userGuid); bool unsubscribed = false; foreach (LetterSubscriber s in userSubscriptions) { if (s.LetterInfoGuid == letterInfoGuid) { subscriptions.Delete(s); unsubscribed = true; LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); } } if (unsubscribed) { lblUnsubscribe.Text = string.Format(CultureInfo.InvariantCulture, Resource.NewsletterUnsubscribeSuccessFormatString, letterInfo.Title); btnUnsubscribeConfirm.Visible = false; lblUnsubscribe.Visible = true; } else { ShowNotFoundMessge(); } }
void grdSubscribers_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { switch (e.CommandName) { case "DeleteSubscriber": string strG = e.CommandArgument.ToString(); if (strG.Length == 36) { Guid subscriptionGuid = new Guid(strG); LetterSubscriber s = subscriptions.Fetch(subscriptionGuid); if (s != null) { subscriptions.Delete(s); } LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); WebUtils.SetupRedirect(this, Request.RawUrl); } break; } }
private void DoSubscribe(LetterInfo letter, string email) { if (email == "*****@*****.**") { return; } //I've been seeing a lot of this from a bot LetterSubscriber s = subscriptions.Fetch(siteSettings.SiteGuid, letter.LetterInfoGuid, email); bool needToSendVerification = false; if (s == null) { s = new LetterSubscriber(); s.SiteGuid = siteSettings.SiteGuid; s.EmailAddress = email; s.LetterInfoGuid = letter.LetterInfoGuid; if (showFormatOptions) { s.UseHtml = rbHtmlFormat.Checked; } else { s.UseHtml = htmlIsDefault; } if ((currentUser != null) && (string.Equals(currentUser.Email, email, StringComparison.InvariantCultureIgnoreCase))) { s.UserGuid = currentUser.UserGuid; s.IsVerified = true; } else { // user is not authenticated but may still exist // attach userguid but don't flag as verified // because we don't know that the user who submited the form is the account owner SiteUser siteUser = SiteUser.GetByEmail(siteSettings, email); if (siteUser != null) { s.UserGuid = siteUser.UserGuid; } } s.IpAddress = SiteUtils.GetIP4Address(); subscriptions.Save(s); LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); if (WebConfigSettings.LogNewsletterSubscriptions) { log.Info(s.EmailAddress + " just subscribed to newsletter " + letter.Title); } if (!s.IsVerified) { needToSendVerification = true; } } else { // we found an existing subscription if (!s.IsVerified) { // if the current authenticated user has the same email mark it as verified if ((currentUser != null) && (string.Equals(currentUser.Email, email, StringComparison.InvariantCultureIgnoreCase))) { s.UserGuid = currentUser.UserGuid; if (showFormatOptions) { s.UseHtml = rbHtmlFormat.Checked; } subscriptions.Save(s); subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty); } else if (s.BeginUtc < DateTime.UtcNow.AddDays(-WebConfigSettings.NewsletterReVerifcationAfterDays)) { // if the user never verifed before and its been at least x days go ahead and send another chance to verify needToSendVerification = true; // TODO: maybe we should log this in case some spam script is using the same email over and over // or maybe we should add a verification sent count on subscription } } } //added 2012-05-16 to support intranet scenarios where verification is not required if (!WebConfigSettings.NewsletterRequireVerification) { if (!s.IsVerified) { s.IsVerified = true; subscriptions.Save(s); } needToSendVerification = false; } if (needToSendVerification) { NewsletterHelper.SendSubscriberVerificationEmail( siteRoot, email, s.SubscribeGuid, letter, siteSettings); } }
private void DoSubscribe(LetterInfo letter, string email) { LetterSubscriber s = subscriptions.Fetch(siteSettings.SiteGuid, letter.LetterInfoGuid, email); bool needToSendVerification = false; if (s == null) { s = new LetterSubscriber(); s.SiteGuid = siteSettings.SiteGuid; s.EmailAddress = email; s.LetterInfoGuid = letter.LetterInfoGuid; if (showFormatOptions) { s.UseHtml = rbHtmlFormat.Checked; } else { s.UseHtml = htmlIsDefault; } if ((currentUser != null) && (string.Equals(currentUser.Email, email, StringComparison.InvariantCultureIgnoreCase))) { s.UserGuid = currentUser.UserGuid; s.IsVerified = true; } else { // user is not authenticated but may still exist // attach userguid but don't flag as verified // because we don't know that the user who submited the form is the account owner SiteUser siteUser = SiteUser.GetByEmail(siteSettings, email); if (siteUser != null) { s.UserGuid = siteUser.UserGuid; } } s.IpAddress = SiteUtils.GetIP4Address(); subscriptions.Save(s); LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); if (!s.IsVerified) { needToSendVerification = true; } } else { // we found an existing subscription if (!s.IsVerified) { // if the current authenticated user has the same email mark it as verified if ((currentUser != null) && (string.Equals(currentUser.Email, email, StringComparison.InvariantCultureIgnoreCase))) { s.UserGuid = currentUser.UserGuid; if (showFormatOptions) { s.UseHtml = rbHtmlFormat.Checked; } subscriptions.Save(s); subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty); } else if (s.BeginUtc < DateTime.UtcNow.AddDays(-WebConfigSettings.NewsletterReVerifcationAfterDays)) { // if the user never verifed before and its been at least x days go ahead and send another chance to verify needToSendVerification = true; // TODO: maybe we should log this in case some spam script is using the same email over and over // or maybe we should add a verification sent count on subscription } } } if (needToSendVerification) { string verificationTemplate = ResourceHelper.GetMessageTemplate(SiteUtils.GetDefaultCulture(), "NewsletterVerificationEmailMessage.config"); string confirmLink = siteRoot + "/eletter/Confirm.aspx?s=" + s.SubscribeGuid.ToString(); string messageBody = verificationTemplate.Replace("{NewsletterName}", letter.Title).Replace("{ConfirmationLink}", confirmLink).Replace("{SiteLink}", siteRoot); string subject = string.Format(CultureInfo.InvariantCulture, Resource.NewsletterVerifySubjectFormat, letter.Title); EmailMessageTask messageTask = new EmailMessageTask(SiteUtils.GetSmtpSettings()); messageTask.SiteGuid = siteSettings.SiteGuid; if (letter.FromAddress.Length > 0) { messageTask.EmailFrom = letter.FromAddress; } else { messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; } messageTask.EmailTo = email; messageTask.Subject = subject; messageTask.TextBody = messageBody; messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); } }