示例#1
0
        /// <summary>
        /// people can subscribe to the newsletters without registering on the site. This method is used to attach those existing subscriptions to the user upon registration
        /// </summary>
        /// <param name="siteUser"></param>
        public static void ClaimExistingSubscriptions(SiteUser siteUser)
        {
            SubscriberRepository subscriptions = new SubscriberRepository();
            List<LetterSubscriber> userSubscriptions = subscriptions.GetListByEmail(siteUser.SiteGuid, siteUser.Email);

            foreach (LetterSubscriber s in userSubscriptions)
            {

                if (s.UserGuid != siteUser.UserGuid)
                {
                    s.UserGuid = siteUser.UserGuid;
                    subscriptions.Save(s);
                }

                if (!s.IsVerified)
                {
                    subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty);
                    LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);

                }

            }

            List<LetterSubscriber> memberSubscriptions = subscriptions.GetListByUser(siteUser.SiteGuid, siteUser.UserGuid);

            RemoveDuplicates(memberSubscriptions);

            // commented out 2012-11-16 since we now give the user a chance to opt in the registration
            // then we should not force him in if he chose not to opt in

            //if (memberSubscriptions.Count == 0)
            //{
            //    string ipAddress = SiteUtils.GetIP4Address();
            //    //user has no previous subscriptions and just registered
            //    // lets give him the site subscriptions that are configured for opting in new users by default
            //    List<LetterInfo> allNewsletters = LetterInfo.GetAll(siteUser.SiteGuid);
            //    foreach (LetterInfo l in allNewsletters)
            //    {
            //        if ((l.ProfileOptIn) && (l.AvailableToRoles.Contains("All Users;")))
            //        {
            //            LetterSubscriber s = new LetterSubscriber();
            //            s.SiteGuid = siteUser.SiteGuid;
            //            s.LetterInfoGuid = l.LetterInfoGuid;
            //            s.UserGuid = siteUser.UserGuid;
            //            s.EmailAddress = siteUser.Email;
            //            s.IsVerified = true;
            //            s.UseHtml = true;
            //            s.IpAddress = ipAddress;
            //            subscriptions.Save(s);

            //        }

            //    }

            //}
        }
示例#2
0
        public bool DeleteUser()
        {
            if(this.siteSettings.ReallyDeleteUsers)
            {
                SubscriberRepository subscriptions = new SubscriberRepository();

                List<LetterSubscriber> subs = subscriptions.GetListByUser(siteSettings.SiteGuid, userGuid);
                foreach (LetterSubscriber subscription in subs)
                {
                    subscriptions.Delete(subscription);
                    LetterInfo.UpdateSubscriberCount(subscription.LetterInfoGuid);
                }

                UserLocation.DeleteByUser(userGuid);
                UserPage.DeleteByUser(userGuid);
                DBSiteUser.DeletePropertiesByUser(userGuid);

                bool result = DBSiteUser.DeleteUser(this.userID);
                if(result)
                {
                    Role.DeleteUserRoles(this.userID);

                }
                return result;
            }
            else
            {
                return DBSiteUser.FlagAsDeleted(this.userID);
            }
        }
示例#3
0
        private void RunTask()
        {
            // this is where the work gets done

            // Get a data table of up to 1000 users
            // who have not opted in but also have not previously
            // opted out and have valid email accounts and account is not locked
            DataTable dataTable = GetData();

            double completeRatio = .5;

            if (dataTable.Rows.Count == 0)
            {
                completeRatio = 1; //complete
                ReportStatus(completeRatio);
                return;

            }

            SubscriberRepository repository = new SubscriberRepository();

            int count = 0;

            foreach (DataRow row in dataTable.Rows)
            {
                Guid userGuid = new Guid(row["UserGuid"].ToString());
                string email = row["email"].ToString();

                LetterSubscriber s = new LetterSubscriber();
                s.SiteGuid = SiteGuid;
                s.UserGuid = userGuid;
                s.EmailAddress = email;
                s.LetterInfoGuid = LetterInfoGuid;
                s.UseHtml = true;
                s.IsVerified = true;

                repository.Save(s);

                count += 1;

                if (count > 20)
                {
                    ReportStatus(completeRatio);
                    count = 0;
                }

            }

            LetterInfo.UpdateSubscriberCount(LetterInfoGuid);
            ReportStatus(completeRatio);

            // repeat until the table comes back with 0 rows
            RunTask();
        }
示例#4
0
        public static void VerifyExistingSubscriptions(SiteUser siteUser)
        {
            SubscriberRepository subscriptions = new SubscriberRepository();
            List<LetterSubscriber> userSubscriptions = subscriptions.GetListByUser(siteUser.SiteGuid, siteUser.UserGuid);
            foreach (LetterSubscriber s in userSubscriptions)
            {

                if (!s.IsVerified)
                {
                    subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty);
                    LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);

                }

            }
        }
示例#5
0
        public static void RemoveDuplicates(List<LetterSubscriber> userSubscriptions)
        {
            SubscriberRepository subscriptions = new SubscriberRepository();
            List<LetterSubscriber> cleanSubscriptions = new List<LetterSubscriber>();
            List<LetterSubscriber> duplicates = new List<LetterSubscriber>();

            foreach (LetterSubscriber s in userSubscriptions)
            {
                if (!ContainsSubscription(cleanSubscriptions, s.LetterInfoGuid))
                {
                    cleanSubscriptions.Add(s);

                }
                else
                {
                    duplicates.Add(s);
                }

            }

            foreach (LetterSubscriber s in duplicates)
            {
                subscriptions.Delete(s, false);
                LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);

            }
        }
示例#6
0
        private void RunTask()
        {
            Letter letter = new Letter(this.letterGuid);
            if (letter.LetterGuid == Guid.Empty)
            {
                log.Error("LetterSendTask letter not found so ending.");
                ReportStatus();
                return;
            }
            if (letter.SendCompleteUtc > DateTime.MinValue)
            {
                log.Error("LetterSendTask SendCompleteUtc already set so ending.");
                ReportStatus();
                return;
            }
            if (letter.SendClickedUtc == DateTime.MinValue)
            {
                log.Error("LetterSendTask SendClickedUtc has an invalid value so ending.");
                ReportStatus();
                return;
            }

            LetterInfo letterInfo = new LetterInfo(letter.LetterInfoGuid);
            SubscriberRepository subscriptions = new SubscriberRepository();

            if (WebConfigSettings.NewsletterTestMode)
            {
                testMode = true;
                log.Info("using NewsletterTestMode=true in config so no real emails will be sent for newsletter " + letterInfo.Title);
            }

            // TODO: this could be a very large recordset if the list is very large
            // might be better to get a page at a time instead of all at once.
            List<LetterSubscriber> subscribers
                = subscriptions.GetSubscribersNotSentYet(
                letter.LetterGuid,
                letter.LetterInfoGuid);

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(reportingFrequency);
            totalSubscribersToSend = subscribers.Count;

            if ((totalSubscribersToSend > 0) && (letter.SendStartedUtc == DateTime.MinValue))
            {
                letter.TrackSendStarted();
            }

            if (totalSubscribersToSend < 100) { testSleepMilliseconds = 3000; }
            if (totalSubscribersToSend > 300) { testSleepMilliseconds = 500;}
            if (totalSubscribersToSend > 500) { testSleepMilliseconds = 100; }

            SmtpSettings smtpSettings = new SmtpSettings();
            smtpSettings.Password = password;
            smtpSettings.Port = port;
            smtpSettings.PreferredEncoding = preferredEncoding;
            smtpSettings.RequiresAuthentication = requiresAuthentication;
            smtpSettings.UseSsl = useSsl;
            smtpSettings.User = user;
            smtpSettings.Server = server;
            smtpSettings.AddBulkMailHeader = true;

            if (maxToSendPerMinute == 0) //not limit
            {
                foreach (LetterSubscriber subscriber in subscribers)
                {
                    SendLetter(smtpSettings, letterInfo, letter, subscriber);
                    subscribersSentSoFar += 1;

                    if (DateTime.UtcNow > nextStatusUpdateTime)
                        ReportStatus();

                }
            }
            else
            {
                int sentCount = 0;
                foreach (LetterSubscriber subscriber in subscribers)
                {
                    SendLetter(smtpSettings, letterInfo, letter, subscriber);
                    subscribersSentSoFar += 1;
                    sentCount += 1;

                    if (DateTime.UtcNow > nextStatusUpdateTime)
                        ReportStatus();

                    if (sentCount == maxToSendPerMinute)
                    {
                        ReportSleeping();
                        Thread.Sleep(60000); //sleep 1 minute
                        sentCount = 0;
                    }

                }
            }

            ReportStatus();
        }