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;
            }
        }
Esempio n. 2
0
        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);
            }
        }