private SubscriberInfo CreateSubscriber( string email, string firstName, string lastName, string fullName, ContactInfo contact) { var subscriberByEmail = SubscriberInfoProvider.GetSubscriberByEmail(email, _mSite.SiteID); if (subscriberByEmail != null) { return(subscriberByEmail); } var subscriber = new SubscriberInfo { SubscriberEmail = email, SubscriberFirstName = firstName, SubscriberLastName = lastName, SubscriberSiteID = _mSite.SiteID, SubscriberFullName = fullName, SubscriberRelatedID = contact.ContactID, SubscriberType = "om.contact" }; SubscriberInfoProvider.SetSubscriberInfo(subscriber); return(subscriber); }
public void ConfirmSubscription_Hash_DateTime_SubscriptionIsConfirmed() { var email = "a-guid-" + Guid.NewGuid() + "@domain.com"; var dateTime = DateTime.Now; var contact = GetContact(email); mNewsletterSubscriptionService.Subscribe(contact, mNewsletter, mNewsletterSubscriptionSettings); // Get the expected subscriber and binding to newsletter so that hash for their subscription confirmation can be faked // (the newsletters API allows to retrieve current hash, but not the corresponding timestamp which is necessary to pass the validation). var expectedSubscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, mSite.SiteID); var confirmationHash = SecurityHelper.GenerateConfirmationEmailHash(mNewsletter.NewsletterGUID + "|" + expectedSubscriber.SubscriberGUID, dateTime); var expectedSubscriberNewsletter = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(expectedSubscriber.SubscriberID, mNewsletter.NewsletterID); expectedSubscriberNewsletter.SubscriptionApprovalHash = confirmationHash; SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(expectedSubscriberNewsletter); var approvalResult = mNewsletterSubscriptionService.ConfirmSubscription(expectedSubscriberNewsletter.SubscriptionApprovalHash, false, dateTime); // Retrieve the subscriber-newsletter binding again so that approval state can be validated expectedSubscriberNewsletter = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(expectedSubscriber.SubscriberID, mNewsletter.NewsletterID); Assert.AreEqual(ApprovalResult.Success, approvalResult, "Subscription confirmation was not successful."); Assert.IsTrue(expectedSubscriberNewsletter.SubscriptionApproved, $"Subscription is not approved after confirmation."); }
public void ConfirmSubscription_SubscriptionIsNotConfirmedByDefault() { var email = "a-guid-" + Guid.NewGuid() + "@domain.com"; var contact = GetContact(email); mNewsletterSubscriptionService.Subscribe(contact, mNewsletter, mNewsletterSubscriptionSettings); var expectedSubscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, mSite.SiteID); var expectedSubscriberNewsletter = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(expectedSubscriber.SubscriberID, mNewsletter.NewsletterID); Assert.IsFalse(expectedSubscriberNewsletter.SubscriptionApproved, $"Subscription must not be approved when double opt-in is enabled."); }
public void Subscribe_Contact_ContactIsSubscribed() { var email = "a-guid-" + Guid.NewGuid() + "@domain.com"; var contact = GetContact(email); var result = mNewsletterSubscriptionService.Subscribe(contact, mNewsletter, mNewsletterSubscriptionSettings); var expectedSubscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, mSite.SiteID); CMSAssert.All( () => Assert.IsTrue(result, "New subscription is expected."), () => Assert.NotNull(expectedSubscriber, $"No subscriber for email '{email}' was created.") ); }
protected void btnSubmit_Click(object sender, EventArgs e) { string email = txtEmail.Text.Trim(); string result = new Validator().IsEmail(email, GetString("unsubscribe.invalidemailformat")).Result; if (String.IsNullOrEmpty(result)) { bool requestSent = false; var site = SiteContext.CurrentSite; var newsletter = NewsletterInfoProvider.GetNewsletterInfo(NewsletterName, site.SiteID); if (newsletter != null) { var unsubscriptionProvider = Service <IUnsubscriptionProvider> .Entry(); if (!unsubscriptionProvider.IsUnsubscribedFromSingleNewsletter(email, newsletter.NewsletterID, newsletter.NewsletterSiteID)) { var subscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, site.SiteID); if (subscriber != null) { SendUnsubscriptionRequest(subscriber, newsletter, site.SiteName); requestSent = true; } } } // Unsubscription failed if none confirmation e-mail was sent if (!requestSent) { // Use default error message if none is specified result = String.IsNullOrEmpty(ErrorText) ? GetString("unsubscribe.notsubscribed") : ErrorText; } } // Display error message if set if (!string.IsNullOrEmpty(result)) { lblError.Text = result; lblError.Visible = true; } else { // Display unsubscription confirmation lblInfo.Visible = true; lblInfo.Text = String.IsNullOrEmpty(ResultText) ? GetString("unsubscribe.confirmtext") : ResultText; lblError.Visible = false; txtEmail.Visible = false; btnSubmit.Visible = false; } }
public void Subscribe_NewContact_ContactIsStoredToDBAndSubscribed() { var email = "a-guid-" + Guid.NewGuid() + "@domain.com"; var contact = new ContactInfo() { ContactEmail = email, }; var result = mNewsletterSubscriptionService.Subscribe(contact, mNewsletter, mNewsletterSubscriptionSettings); var expectedSubscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, mSite.SiteID); var subscribedContact = ContactInfoProvider.GetContacts().WhereEquals("ContactEmail", email); CMSAssert.All( () => Assert.IsTrue(result, "New subscription is expected."), () => Assert.NotNull(subscribedContact, $"No contact for email '{email}' was created."), () => Assert.NotNull(expectedSubscriber, $"No subscriber for email '{email}' was created.") ); }
private SubscriberInfo CreateSubscriber(string email, string firstName, string lastName, string fullName, ContactInfo contact) { var subscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, site.SiteID); if (subscriber != null) { return(subscriber); } subscriber = new SubscriberInfo { SubscriberEmail = email, SubscriberFirstName = firstName, SubscriberLastName = lastName, SubscriberSiteID = site.SiteID, SubscriberFullName = fullName, SubscriberRelatedID = contact.ContactID, SubscriberType = PredefinedObjectType.CONTACT }; SubscriberInfo.Provider.Set(subscriber); return(subscriber); }