コード例 #1
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            int siteId = 0;

            // Get current id
            if (CMSContext.CurrentSite != null)
            {
                siteId = CMSContext.CurrentSiteID;
            }

            // Get subscriber and newsletter guid from query string
            Guid   subscriberGuid   = QueryHelper.GetGuid("subscriberguid", Guid.Empty);
            Guid   newsletterGuid   = QueryHelper.GetGuid("newsletterguid", Guid.Empty);
            Guid   issueGuid        = QueryHelper.GetGuid("issueguid", Guid.Empty);
            string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty);
            int    issueId          = QueryHelper.GetInteger("issueid", 0);
            int    contactId        = QueryHelper.GetInteger("contactid", 0);

            string   requestTime = QueryHelper.GetString("datetime", string.Empty);
            DateTime datetime    = DateTimeHelper.ZERO_TIME;

            // Get date and time
            if (!string.IsNullOrEmpty(requestTime))
            {
                try
                {
                    datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null);
                }
                catch
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("newsletter.unsubscribefailed");
                    return;
                }
            }

            // Check whether both guid exists
            if ((subscriberGuid != Guid.Empty) && (newsletterGuid != Guid.Empty))
            {
                SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberGuid, siteId);
                if (subscriber == null)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscribe.SubscriberDoesNotExist");
                    return;
                }
                // Show error message if subscriber type is 'Role'
                if (!string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.EqualsCSafe(SiteObjectType.ROLE, true))
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscriber.CannotUnsubscribeRole");
                    return;
                }

                NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterGuid, siteId);
                if (newsletter == null)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscribe.NewsletterDoesNotExist");
                    return;
                }

                // Check whether subscription is valid
                if (SubscriberInfoProvider.IsSubscribed(subscriber.SubscriberID, newsletter.NewsletterID))
                {
                    bool isSubscribed = true;

                    if (string.IsNullOrEmpty(subscriber.SubscriberType) || !subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true))
                    {
                        // Unsubscribe action
                        SubscriberInfoProvider.Unsubscribe(subscriber.SubscriberID, newsletter.NewsletterID, SendConfirmationEmail);
                    }
                    else
                    {
                        // Check if the contact group member has unsubscription activity for the specified newsletter
                        isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, newsletter.NewsletterID, siteId);
                    }

                    if (isSubscribed)
                    {
                        // Log newsletter unsubscription activity
                        LogActivity(subscriber, subscriber.SubscriberID, newsletter.NewsletterID, siteId, issueId, issueGuid, contactId);

                        // Display confirmation
                        DisplayConfirmation();
                    }
                    else
                    {
                        // Contact group member is already unsubscribed
                        lblError.Visible = true;
                        lblError.Text    = GetString("Unsubscribe.NotSubscribed");
                    }
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscribe.NotSubscribed");
                }
            }
            // Check if subscriptionGUID is supplied
            else if (!string.IsNullOrEmpty(subscriptionHash))
            {
                // Check if given subscription exists
                SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash);
                if ((sni != null) && sni.SubscriptionEnabled)
                {
                    SubscriberInfoProvider.ApprovalResult result = SubscriberInfoProvider.Unsubscribe(subscriptionHash, SendConfirmationEmail, CMSContext.CurrentSiteName, datetime);

                    switch (result)
                    {
                    // Approving subscription was successful
                    case SubscriberInfoProvider.ApprovalResult.Success:
                        bool isSubscribed = true;

                        // Get subscriber
                        SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(sni.SubscriberID);
                        if ((subscriber != null) && !string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true))
                        {
                            // Check if the contact group member has unsubscription activity for the specified newsletter
                            isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, sni.NewsletterID, siteId);
                        }

                        if (isSubscribed)
                        {
                            // Log newsletter unsubscription activity
                            LogActivity(subscriber, subscriber.SubscriberID, sni.NewsletterID, siteId, issueId, issueGuid, contactId);

                            // Display confirmation
                            DisplayConfirmation();
                        }
                        else
                        {
                            // Contact group member is already unsubscribed
                            lblError.Visible = true;
                            lblError.Text    = GetString("Unsubscribe.NotSubscribed");
                        }
                        break;

                    // Subscription was already approved
                    case SubscriberInfoProvider.ApprovalResult.Failed:
                        lblError.Visible = true;
                        lblError.Text    = GetString("newsletter.unsubscribefailed");
                        break;

                    case SubscriberInfoProvider.ApprovalResult.TimeExceeded:
                        lblError.Visible = true;
                        lblError.Text    = GetString("newsletter.approval_timeexceeded");
                        break;

                    // Subscription not found
                    default:
                    case SubscriberInfoProvider.ApprovalResult.NotFound:
                        lblError.Visible = true;
                        lblError.Text    = GetString("Unsubscribe.NotSubscribed");
                        break;
                    }
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscribe.NotSubscribed");
                }
            }
            else
            {
                Visible = false;
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// User control items changed event.
    /// </summary>
    protected void UserSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int siteId = SiteContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(selectUser.Value, null);

        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            int userID = ValidationHelper.GetInteger(item, 0);

            // Get subscriber
            SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, userID, siteId);
            if (sb == null)
            {
                // Get user info
                UserInfo ui = UserInfoProvider.GetUserInfo(userID);
                if (ui == null)
                {
                    continue;
                }

                // Create new subscriber of user type
                sb = new SubscriberInfo();
                sb.SubscriberFirstName = ui.FullName;
                sb.SubscriberFullName  = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName);
                sb.SubscriberSiteID    = siteId;
                sb.SubscriberType      = UserInfo.OBJECT_TYPE;
                sb.SubscriberRelatedID = userID;

                CheckPermissionsForSubscriber(sb);

                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }

            // If subscriber exists and is not subscribed, subscribe him
            if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, mNewsletter.NewsletterID))
            {
                try
                {
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, mNewsletter.NewsletterID, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                }
                catch (InvalidOperationException ex)
                {
                    ShowError(ex.Message);
                }
            }
        }

        selectUser.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #3
0
        /// <summary>
        /// Unsubscribes subscriber.
        /// </summary>
        /// <param name="newsletterGuid">Newsletter unique identifier</param>
        /// <param name="subscriberGuid">Subscriber unique identifier</param>
        /// <param name="issueGuid">Issue unique identifier</param>
        /// <param name="unsubscribeFromAll">If true, subscriber is unsubscribed from all marketing materials</param>
        /// <param name="additionalInformation">Additional information (status message etc.)</param>
        /// <returns>Returns true if unsubscription was successful</returns>
        private bool UnsubscribeInternal(Guid newsletterGuid, Guid subscriberGuid, Guid issueGuid, bool unsubscribeFromAll, out string additionalInformation)
        {
            // Creates required Services
            var subscriptionService = Service <ISubscriptionService> .Entry();

            var unSubscriptionProvider = Service <IUnsubscriptionProvider> .Entry();

            // Validates Subscriber and Newsletter GUIDs
            if ((subscriberGuid == Guid.Empty) || (newsletterGuid == Guid.Empty))
            {
                // Either SubscriberGUID or NewsletterGUID was not supplied, don't unsubscribe
                additionalInformation = ResHelper.GetString("TestMvcDemo.News.InvallidUnsubscriptionLink");
                return(false);
            }

            // Gets information about subscriber, newsletter and issue
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberGuid, SiteId);
            NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterGuid, SiteId);
            IssueInfo      issue      = IssueInfoProvider.GetIssueInfo(issueGuid, SiteId);

            if ((subscriber == null) || (newsletter == null) || (issue == null))
            {
                additionalInformation = ResHelper.GetString("TestMvcDemo.News.InvallidUnsubscriptionLink");
                return(false);
            }

            int?issueId = issue.IssueID;

            // Creates new transaction for saving subscriber's information
            using (var tr = new CMSTransactionScope())
            {
                try
                {
                    if (unsubscribeFromAll)
                    {
                        // Unsubscribes if not already unsubscribed
                        if (!unSubscriptionProvider.IsUnsubscribedFromAllNewsletters(subscriber.SubscriberEmail, newsletter.NewsletterSiteID))
                        {
                            subscriptionService.UnsubscribeFromAllNewsletters(subscriber.SubscriberEmail, SiteId, issueId);
                            tr.Commit();
                        }

                        additionalInformation = ResHelper.GetString("TestMvcDemo.News.UnsubscribedAll");
                        return(true);
                    }

                    // Unsubscribes if not already unsubscribed
                    if (!unSubscriptionProvider.IsUnsubscribedFromSingleNewsletter(subscriber.SubscriberEmail, newsletter.NewsletterID, newsletter.NewsletterSiteID))
                    {
                        subscriptionService.UnsubscribeFromSingleNewsletter(subscriber.SubscriberEmail, newsletter.NewsletterID, issueId);
                        tr.Commit();
                    }

                    additionalInformation = ResHelper.GetString("TestMvcDemo.News.Unsubscribed");
                    return(true);
                }
                catch (Exception exception)
                {
                    Service <IEventLogService> .Entry().LogException("Newsletters", "Unsubscribe", exception);

                    additionalInformation = ResHelper.GetString("newsletter.unsubscribefailed");
                    return(false);
                }
            }
        }
コード例 #4
0
    /// <summary>
    /// Load data.
    /// </summary>
    public void LoadData()
    {
        if (StopProcessing)
        {
            // Hide control
            Visible = false;
        }
        else
        {
            SetContext();

            // Get specified user if used instead of current user
            if (UserID > 0)
            {
                userInfo = UserInfoProvider.GetUserInfo(UserID);
            }
            else
            {
                userInfo = MembershipContext.AuthenticatedUser;
            }

            // Get specified site ID instead of current site ID
            int siteId = 0;
            if (SiteID > 0)
            {
                siteId = SiteID;
            }
            else
            {
                siteId = SiteContext.CurrentSiteID;
            }

            usNewsletters.WhereCondition      = "NewsletterSiteID = " + siteId;
            usNewsletters.OnSelectionChanged += new EventHandler(usNewsletters_OnSelectionChanged);
            usNewsletters.IsLiveSite          = IsLiveSite;

            userIsIdentified = (userInfo != null) && (!userInfo.IsPublic()) && (ValidationHelper.IsEmail(userInfo.Email) || ValidationHelper.IsEmail(userInfo.UserName));
            if (userIsIdentified)
            {
                usNewsletters.Visible = true;

                // Try to get subscriber info with specified e-mail
                subscriber = SubscriberInfoProvider.GetSubscriberInfo(userInfo.Email, siteId);
                if (subscriber == null)
                {
                    // Try to get subscriber info according to user info
                    subscriber = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, userInfo.UserID, siteId);
                }

                // Get user e-mail address
                if (subscriber != null)
                {
                    subscriberEmail = subscriber.SubscriberEmail;

                    // Get selected newsletters
                    DataSet ds = SubscriberNewsletterInfoProvider.GetSubscriberNewsletters().WhereEquals("SubscriberID", subscriber.SubscriberID).Column("NewsletterID");
                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        currentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "NewsletterID"));
                    }

                    // Load selected newsletters
                    if (!RequestHelper.IsPostBack() || !string.IsNullOrEmpty(DataHelper.GetNewItemsInList(SelectorValue, currentValues)))
                    {
                        usNewsletters.Value = currentValues;
                    }
                }

                // Try to get email address from user data
                if (string.IsNullOrEmpty(subscriberEmail))
                {
                    if (ValidationHelper.IsEmail(userInfo.Email))
                    {
                        subscriberEmail = userInfo.Email;
                    }
                    else if (ValidationHelper.IsEmail(userInfo.UserName))
                    {
                        subscriberEmail = userInfo.UserName;
                    }
                }
            }
            else
            {
                usNewsletters.Visible = false;

                if ((UserID > 0) && (MembershipContext.AuthenticatedUser.UserID == UserID))
                {
                    ShowInformation(GetString("MySubscriptions.CannotIdentify"));
                }
                else
                {
                    if (!IsLiveSite)
                    {
                        // It's located in Admin/Users/Subscriptions
                        lblText.ResourceString = "MySubscriptions.EmailCommunicationDisabled";
                    }
                    else
                    {
                        ShowInformation(GetString("MySubscriptions.CannotIdentifyUser"));
                    }
                }
            }

            ReleaseContext();
        }
    }
コード例 #5
0
    /// <summary>
    /// Roles control items changed event.
    /// </summary>
    protected void RolesSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int roleID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;
        RoleInfo       ri       = null;
        int            siteId   = CMSContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(selectRole.Value, null);

        // Get added items
        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                roleID = ValidationHelper.GetInteger(item, 0);

                // Get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.ROLE, roleID, siteId);
                if (sb == null)
                {
                    // Get role info and copy display name to new subscriber
                    ri = RoleInfoProvider.GetRoleInfo(roleID);
                    if ((ri == null) || (ri.SiteID != siteId))
                    {
                        continue;
                    }

                    // Create new subscriber of role type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = ri.DisplayName;
                    // Full name consists of "role " and role display name
                    sb.SubscriberFullName  = string.Concat("Role '", ri.DisplayName, "'");
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = SiteObjectType.ROLE;
                    sb.SubscriberRelatedID = roleID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false);
                    }
                    catch
                    {
                    }
                }
            }
        }

        selectRole.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #6
0
    /// <summary>
    /// Contact items selected event handler.
    /// </summary>
    protected void ContactSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cSelector == null)
        {
            return;
        }
        int siteId = SiteContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(cSelector.Value, null);

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            // Get contact ID
            int contactID = ValidationHelper.GetInteger(item, 0);

            // Try to get subscriber
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.CONTACT, contactID, siteId);
            if (subscriber == null)
            {
                // Get contact's info
                DataSet contactData = ModuleCommands.OnlineMarketingGetContactForNewsletters(contactID, "ContactFirstName,ContactMiddleName,ContactLastName,ContactEmail");
                if (DataHelper.DataSourceIsEmpty(contactData))
                {
                    continue;
                }

                string firstName  = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactFirstName"], string.Empty);
                string lastName   = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactLastName"], string.Empty);
                string middleName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactMiddleName"], string.Empty);
                string email      = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactEmail"], string.Empty);

                // Create new subscriber of contact type
                subscriber = new SubscriberInfo();
                subscriber.SubscriberFirstName = firstName;
                subscriber.SubscriberLastName  = lastName;
                subscriber.SubscriberEmail     = email;
                subscriber.SubscriberFullName  = new SubscriberFullNameFormater().GetContactSubscriberName(firstName, middleName, lastName);
                subscriber.SubscriberSiteID    = siteId;
                subscriber.SubscriberType      = PredefinedObjectType.CONTACT;
                subscriber.SubscriberRelatedID = contactID;

                CheckPermissionsForSubscriber(subscriber);

                SubscriberInfoProvider.SetSubscriberInfo(subscriber);
            }

            if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID))
            {
                mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings()
                {
                    SendConfirmationEmail = chkSendConfirmation.Checked,
                    RequireOptIn          = chkRequireOptIn.Checked,
                    RemoveAlsoUnsubscriptionFromAllNewsletters = false,
                });
            }
        }

        cSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #7
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            return;
        }

        var subscriptionService = Service <ISubscriptionService> .Entry();

        var unsubscriptionProvider = Service <IUnsubscriptionProvider> .Entry();

        var emailHashValidator = Service <IEmailHashValidator> .Entry();

        int siteId = SiteContext.CurrentSiteID;

        // Get data from query string
        Guid   subscriberGuid     = QueryHelper.GetGuid("subscriberguid", Guid.Empty);
        Guid   newsletterGuid     = QueryHelper.GetGuid("newsletterguid", Guid.Empty);
        bool   unsubscribeFromAll = QueryHelper.GetBoolean("unsubscribeFromAll", false);
        string email = QueryHelper.GetString("email", string.Empty);
        string hash  = QueryHelper.GetString("hash", string.Empty);
        bool   isInBackwardCompatibilityMode = (string.IsNullOrEmpty(hash) && (subscriberGuid != Guid.Empty));

        NewsletterContext.UnsubscriptionLinksBackwardCompatibilityMode = isInBackwardCompatibilityMode;

        // Email must be provided and hash must be valid when not in compatibility mode
        if (!isInBackwardCompatibilityMode && !emailHashValidator.ValidateEmailHash(hash, email))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("newsletter.unsubscribefailed");
            return;
        }

        // When backward compatibility mode is used, email is not provided in query string. Get it from subscriber or contact in this case.
        if (isInBackwardCompatibilityMode)
        {
            var subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberGuid, siteId);
            email = GetSubscriberEmail(subscriber, QueryHelper.GetInteger("contactid", 0));

            if (string.IsNullOrEmpty(email))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("Unsubscribe.NotSubscribed");
                return;
            }
        }

        if (!ValidationHelper.IsEmail(email))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("newsletter.unsubscribefailed");
            return;
        }

        int?issueId = GetIssueID(siteId);

        if (unsubscribeFromAll)
        {
            if (!unsubscriptionProvider.IsUnsubscribedFromAllNewsletters(email, siteId))
            {
                subscriptionService.UnsubscribeFromAllNewsletters(email, CurrentSite.SiteID, issueId, SendConfirmationEmail);
            }

            DisplayConfirmationAllUnsubscribed();
        }
        else
        {
            var newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterGuid, siteId);
            if (newsletter == null)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("Unsubscribe.NewsletterDoesNotExist");
                return;
            }

            if (!unsubscriptionProvider.IsUnsubscribedFromSingleNewsletter(email, newsletter.NewsletterID, newsletter.NewsletterSiteID))
            {
                subscriptionService.UnsubscribeFromSingleNewsletter(email, newsletter.NewsletterID, issueId, SendConfirmationEmail);
            }

            DisplayConfirmationSingleUnsubscribed();
        }
    }
コード例 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // If StopProcessing flag is set, do nothing
        if (StopProcessing)
        {
            Visible = false;
            return;
        }

        string   subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty);
        string   requestTime      = QueryHelper.GetString("datetime", string.Empty);
        DateTime datetime         = DateTimeHelper.ZERO_TIME;

        // Get date and time
        if (!string.IsNullOrEmpty(requestTime))
        {
            try
            {
                datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null);
            }
            catch
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_failed");
                return;
            }
        }

        if (string.IsNullOrEmpty(subscriptionHash))
        {
            Visible = false;
            return;
        }

        var approvalService = Service <ISubscriptionApprovalService> .Entry();

        var result = approvalService.ApproveSubscription(subscriptionHash, false, SiteContext.CurrentSiteName, datetime);

        switch (result)
        {
        case ApprovalResult.Success:
            lblInfo.Text = !String.IsNullOrEmpty(SuccessfulApprovalText) ? SuccessfulApprovalText : ResHelper.GetString("newsletter.successful_approval");

            var subscription = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash);
            if (subscription == null)
            {
                return;
            }

            var newsletter = NewsletterInfoProvider.GetNewsletterInfo(subscription.NewsletterID);
            var subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscription.SubscriberID);

            if ((newsletter == null) || (subscriber == null))
            {
                return;
            }

            LogNewsletterSubscriptionActivity(subscriber, newsletter);
            break;

        case ApprovalResult.Failed:
            lblInfo.Text = !String.IsNullOrEmpty(UnsuccessfulApprovalText) ? UnsuccessfulApprovalText : ResHelper.GetString("newsletter.approval_failed");
            break;

        case ApprovalResult.TimeExceeded:
            lblInfo.Text = !String.IsNullOrEmpty(UnsuccessfulApprovalText) ? UnsuccessfulApprovalText : ResHelper.GetString("newsletter.approval_timeexceeded");
            break;

        case ApprovalResult.AlreadyApproved:
            lblInfo.Text = !String.IsNullOrEmpty(SuccessfulApprovalText) ? SuccessfulApprovalText : ResHelper.GetString("newsletter.successful_approval");
            break;

        // Subscription not found
        default:
            lblInfo.Text = !String.IsNullOrEmpty(UnsuccessfulApprovalText) ? UnsuccessfulApprovalText : ResHelper.GetString("newsletter.approval_invalid");
            break;
        }
    }
コード例 #9
0
    protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row          = (DataRowView)parameter;
        int         subscriberId = 0;

        switch (sourceName)
        {
        case "name":
            subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
            string name = null;
            if (subscriberId == 0)
            {
                // Get full name for contact group member (contact)
                name = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberFullName"), string.Empty);

                // Return encoded name
                return(HTMLHelper.HTMLEncode(name));
            }
            else
            {
                // Add the field transformation control that handles the translation
                var tr = new ObjectTransformation("newsletter.subscriber", subscriberId);
                tr.Transformation = "SubscriberFullName";

                return(tr);
            }

        case "email":
            subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
            string email = null;
            if (subscriberId == 0)
            {
                // Get email for contact group member (contact)
                email = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberEmail"), string.Empty);
            }
            else
            {
                SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberId);
                if (subscriber != null)
                {
                    if (subscriber.SubscriberType == null)
                    {
                        // Get email for classic subscriber
                        email = subscriber.SubscriberEmail;
                    }
                    else
                    {
                        switch (subscriber.SubscriberType)
                        {
                        case PredefinedObjectType.USER:
                            UserInfo user = UserInfoProvider.GetUserInfo(subscriber.SubscriberRelatedID);
                            if (user != null)
                            {
                                // Get email for user subscriber
                                email = user.Email;
                            }
                            break;

                        case PredefinedObjectType.CONTACT:
                            DataSet ds = ModuleCommands.OnlineMarketingGetContactForNewsletters(subscriber.SubscriberRelatedID, "ContactEmail");
                            if (!DataHelper.DataSourceIsEmpty(ds))
                            {
                                // Get email from contact subscriber
                                email = ValidationHelper.GetString(ds.Tables[0].Rows[0]["ContactEmail"], string.Empty);
                            }
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(email))
            {
                // Return encoded email
                email = HTMLHelper.HTMLEncode(email);
            }

            return(email);

        default:
            return(parameter);
        }
    }
コード例 #10
0
    private void usNewsletters_OnSelectionChanged(object sender, EventArgs e)
    {
        // Check 'EcommerceModify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Ecommerce", "EcommerceModify"))
        {
            // Check 'ModifyCustomers' permission if don't have general ecommerce modify permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Ecommerce", "ModifyCustomers"))
            {
                RedirectToCMSDeskAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
            }
        }

        // Check if a customer has a valid email
        if ((email != null) && (email.Trim() != string.Empty) && (ValidationHelper.IsEmail(email)))
        {
            // Check whether subscriber already exist
            SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(email, siteId);
            if (sb == null)
            {
                // Create new subscriber
                sb = new SubscriberInfo();
                sb.SubscriberEmail     = email;
                sb.SubscriberFirstName = firstName;
                sb.SubscriberLastName  = lastName;
                sb.SubscriberFullName  = (firstName + " " + lastName).Trim();
                sb.SubscriberSiteID    = siteId;
                sb.SubscriberGUID      = Guid.NewGuid();
                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }

            // Remove old items
            string newValues = ValidationHelper.GetString(usNewsletters.Value, null);
            string items     = DataHelper.GetNewItemsInList(newValues, currentValues);
            if (!String.IsNullOrEmpty(items))
            {
                string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (newItems != null)
                {
                    foreach (string item in newItems)
                    {
                        int newsletterId = ValidationHelper.GetInteger(item, 0);

                        // If subscriber is subscribed, unsubscribe him
                        if (SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))
                        {
                            SubscriberInfoProvider.Unsubscribe(sb.SubscriberID, newsletterId);
                        }
                    }
                }
            }

            // Add new items
            items = DataHelper.GetNewItemsInList(currentValues, newValues);
            if (!String.IsNullOrEmpty(items))
            {
                string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (newItems != null)
                {
                    foreach (string item in newItems)
                    {
                        int newsletterId = ValidationHelper.GetInteger(item, 0);

                        // If subscriber is not subscribed, subscribe him
                        if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))
                        {
                            SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now);
                        }
                    }
                }
            }

            // Display information about successful (un)subscription
            ShowChangesSaved();
        }
    }
コード例 #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Guid subscriberGuid    = QueryHelper.GetGuid("subscriberguid", Guid.Empty);
        int  newsletterIssueId = QueryHelper.GetInteger("issueid", 0);

        // Get newsletter issue
        IssueInfo issue = IssueInfoProvider.GetIssueInfo(newsletterIssueId);

        if (issue == null)
        {
            return;
        }

        // Get subscriber
        SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberGuid, CMSContext.CurrentSiteID);

        // Get the newsletter
        NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(issue.IssueNewsletterID);

        if (news == null)
        {
            return;
        }

        // Get site default culture
        string culture = CultureHelper.GetDefaultCulture(CMSContext.CurrentSiteName);

        // Ensure preview in default site culture
        // Keep old culture
        CultureInfo oldUICulture = Thread.CurrentThread.CurrentUICulture;

        // Set current culture
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

        string htmlPage = String.Empty;

        try
        {
            if (subscriber != null)
            {
                // Get subscriber's member (different for user or role subscribers)
                SortedDictionary <int, SubscriberInfo> subscribers = SubscriberInfoProvider.GetSubscribers(subscriber, 1, 0, news.NewsletterID);
                foreach (KeyValuePair <int, SubscriberInfo> item in subscribers)
                {
                    // Get 1st subscriber's member
                    SubscriberInfo sb = item.Value;

                    htmlPage = IssueInfoProvider.GetEmailBody(issue, news, null, sb, true, CMSContext.CurrentSiteName, null, null, null);
                }
            }

            if (string.IsNullOrEmpty(htmlPage))
            {
                htmlPage = IssueInfoProvider.GetEmailBody(issue, news, null, null, true, CMSContext.CurrentSiteName, null, null, null);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            // Set back to old culture
            Thread.CurrentThread.CurrentUICulture = oldUICulture;
        }

        Response.Clear();
        Response.Write(htmlPage);

        RequestHelper.EndResponse();
    }
コード例 #12
0
    /// <summary>
    /// Contact items selected event handler.
    /// </summary>
    protected void ContactSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cSelector == null)
        {
            return;
        }
        int contactID = 0;

        string[]       newItems    = null;
        SubscriberInfo sb          = null;
        int            siteId      = CMSContext.CurrentSiteID;
        string         cType       = PredefinedObjectType.CONTACT;
        DataSet        contactData = null;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(cSelector.Value, null);

        // Get added items
        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                // Get contact ID
                contactID = ValidationHelper.GetInteger(item, 0);

                // Try to get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(cType, contactID, siteId);
                if (sb == null)
                {
                    // Get contact's info
                    contactData = ModuleCommands.OnlineMarketingGetContactForNewsletters(contactID, "ContactFirstName,ContactMiddleName,ContactLastName");
                    if (DataHelper.DataSourceIsEmpty(contactData))
                    {
                        continue;
                    }

                    string firstName  = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactFirstName"], string.Empty);
                    string lastName   = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactLastName"], string.Empty);
                    string middleName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactMiddleName"], string.Empty);

                    // Create new subscriber of contact type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = firstName;
                    sb.SubscriberLastName  = lastName;
                    sb.SubscriberFullName  = string.Format("Contact '{0}{1}{2}'", string.IsNullOrEmpty(firstName) ? string.Empty : firstName + " ", string.IsNullOrEmpty(middleName) ? string.Empty : middleName + " ", lastName);
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = cType;
                    sb.SubscriberRelatedID = contactID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                    }
                    catch
                    {
                    }
                }
            }
        }

        cSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #13
0
    /// <summary>
    /// Contact group items selected event handler.
    /// </summary>
    protected void CGSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cgSelector == null)
        {
            return;
        }
        int groupID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;
        int            siteId   = CMSContext.CurrentSiteID;
        string         cgType   = "om.contactgroup";
        string         cgName   = null;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(cgSelector.Value, null);

        // Get added items
        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                // Get group ID
                groupID = ValidationHelper.GetInteger(item, 0);

                // Try to get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(cgType, groupID, siteId);
                if (sb == null)
                {
                    // Get contact group display name
                    cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID);
                    if (string.IsNullOrEmpty(cgName))
                    {
                        continue;
                    }

                    // Create new subscriber of contact group type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = cgName;
                    // Full name consists of "contact group " and display name
                    sb.SubscriberFullName  = string.Concat("Contact group '", cgName, "'");
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = cgType;
                    sb.SubscriberRelatedID = groupID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false);
                    }
                    catch
                    {
                    }
                }
            }
        }

        cgSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #14
0
    /// <summary>
    /// User control items changed event.
    /// </summary>
    protected void UserSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int userID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;
        UserInfo       ui       = null;
        int            siteId   = CMSContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(selectUser.Value, null);

        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                userID = ValidationHelper.GetInteger(item, 0);

                // Get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.USER, userID, siteId);
                if (sb == null)
                {
                    // Get user info
                    ui = UserInfoProvider.GetUserInfo(userID);
                    if (ui == null)
                    {
                        continue;
                    }

                    // Create new subscriber of user type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = ui.FullName;
                    sb.SubscriberFullName  = "User '" + ui.FullName + "'";
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = SiteObjectType.USER;
                    sb.SubscriberRelatedID = userID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                    }
                    catch
                    {
                    }
                }
            }
        }

        selectUser.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #15
0
    /// <summary>
    /// User control items changed event.
    /// </summary>
    protected void UserSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int siteId = SiteContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(selectUser.Value, null);

        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            int userID = ValidationHelper.GetInteger(item, 0);

            // Get subscriber
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, userID, siteId);
            if (subscriber == null)
            {
                // Get user info
                UserInfo ui = UserInfoProvider.GetUserInfo(userID);
                if (ui == null)
                {
                    continue;
                }

                // Create new subscriber of user type
                subscriber = new SubscriberInfo();
                subscriber.SubscriberFirstName = ui.FullName;
                subscriber.SubscriberFullName  = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName);
                subscriber.SubscriberSiteID    = siteId;
                subscriber.SubscriberType      = UserInfo.OBJECT_TYPE;
                subscriber.SubscriberRelatedID = userID;

                CheckPermissionsForSubscriber(subscriber);

                SubscriberInfoProvider.SetSubscriberInfo(subscriber);
            }

            if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID))
            {
                mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings()
                {
                    SendConfirmationEmail = chkSendConfirmation.Checked,
                    RequireOptIn          = chkRequireOptIn.Checked,
                    RemoveAlsoUnsubscriptionFromAllNewsletters = false,
                });
            }
        }

        selectUser.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #16
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            formElem.StopProcessing = StopProcessing;
            Visible = false;
        }
        else
        {
            isAuthenticated = (CurrentUser != null) && AuthenticationHelper.IsAuthenticated();

            if (AllowUserSubscribers && isAuthenticated && (CurrentUser != null) && (!string.IsNullOrEmpty(CurrentUser.Email)))
            {
                // Hide form for authenticated user who has an email
                formElem.StopProcessing = true;
                formElem.Visible        = false;
            }
            else
            {
                // Get alternative form info
                AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(AlternativeForm);
                if (afi != null)
                {
                    // Init subscriber object
                    SubscriberInfo sb = new SubscriberInfo();
                    if (AllowUserSubscribers && isAuthenticated)
                    {
                        // Prepare user subscriber object for authenticated user without an email
                        // Try to get existing user subscriber
                        sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, CurrentUser.UserID, SiteContext.CurrentSiteID);
                        if (sb == null)
                        {
                            // Prepare new user subscriber with pre-filled data
                            sb = new SubscriberInfo()
                            {
                                SubscriberFirstName = CurrentUser.FirstName,
                                SubscriberLastName  = CurrentUser.LastName,
                                SubscriberFullName  = (CurrentUser.FirstName + " " + CurrentUser.LastName).Trim(),
                                SubscriberType      = UserInfo.OBJECT_TYPE,
                                SubscriberRelatedID = CurrentUser.UserID
                            };
                        }
                    }

                    // Init the form
                    formElem.AlternativeFormFullName = AlternativeForm;
                    formElem.Info                   = sb;
                    formElem.ClearAfterSave         = false;
                    formElem.Visible                = true;
                    formElem.ValidationErrorMessage = SubscriptionErrorMessage;
                    formElem.IsLiveSite             = true;

                    // Reload form if not in PortalEngine environment and if post back
                    if ((StandAlone) && (RequestHelper.IsPostBack()))
                    {
                        formElem.ReloadData();
                    }
                }
                else
                {
                    lblError.Text           = String.Format(GetString("altform.formdoesntexists"), AlternativeForm);
                    lblError.Visible        = true;
                    pnlSubscription.Visible = false;
                }
            }

            // Display/hide captcha
            plcCaptcha.Visible                   = DisplayCaptcha;
            lblCaptcha.ResourceString            = CaptchaText;
            lblCaptcha.AssociatedControlClientID = scCaptcha.InputClientID;

            // Init submit buttons
            if ((UseImageButton) && (!String.IsNullOrEmpty(ImageButtonURL)))
            {
                pnlButtonSubmit.Visible = false;
                pnlImageSubmit.Visible  = true;
                btnImageSubmit.ImageUrl = ImageButtonURL;
            }
            else
            {
                pnlButtonSubmit.Visible = true;
                pnlImageSubmit.Visible  = false;
                btnSubmit.Text          = ButtonText;
            }

            lblInfo.CssClass  = "EditingFormInfoLabel";
            lblError.CssClass = "EditingFormErrorLabel";

            if (formElem != null)
            {
                // Set the live site context
                formElem.ControlContext.ContextName = CMS.ExtendedControls.ControlContext.LIVE_SITE;
            }

            // Init newsletter selector
            InitNewsletterSelector();
        }
    }
コード例 #17
0
    /// <summary>
    /// Contact group items selected event handler.
    /// </summary>
    protected void CGSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cgSelector == null)
        {
            return;
        }
        int siteId = SiteContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(cgSelector.Value, null);

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            // Get group ID
            int groupID = ValidationHelper.GetInteger(item, 0);

            // Try to get subscriber
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.CONTACTGROUP, groupID, siteId);
            if (subscriber == null)
            {
                // Get contact group display name
                string cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID);
                if (string.IsNullOrEmpty(cgName))
                {
                    continue;
                }

                // Create new subscriber of contact group type
                subscriber = new SubscriberInfo();
                subscriber.SubscriberFirstName = cgName;
                // Full name consists of "contact group " and display name
                subscriber.SubscriberFullName  = new SubscriberFullNameFormater().GetContactGroupSubscriberName(cgName);
                subscriber.SubscriberSiteID    = siteId;
                subscriber.SubscriberType      = PredefinedObjectType.CONTACTGROUP;
                subscriber.SubscriberRelatedID = groupID;

                CheckPermissionsForSubscriber(subscriber);

                SubscriberInfoProvider.SetSubscriberInfo(subscriber);
            }

            if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID))
            {
                mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings()
                {
                    SendConfirmationEmail = chkSendConfirmation.Checked,
                    RequireOptIn          = false,
                    RemoveAlsoUnsubscriptionFromAllNewsletters = false,
                });
            }
        }

        cgSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #18
0
    /// <summary>
    /// Save subscriber.
    /// </summary>
    /// <returns>Subscriver info object</returns>
    private SubscriberInfo SaveSubscriber()
    {
        string emailValue = null;
        int    siteId     = SiteContext.CurrentSiteID;

        // Check if a subscriber exists first
        SubscriberInfo sb = null;

        if (AllowUserSubscribers && isAuthenticated)
        {
            // Try to get user subscriber
            sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, CurrentUser.UserID, siteId);
        }
        else
        {
            EditingFormControl txtEmail = formElem.FieldEditingControls["SubscriberEmail"] as EditingFormControl;
            if (txtEmail != null)
            {
                emailValue = ValidationHelper.GetString(txtEmail.Value, String.Empty);
            }

            if (!string.IsNullOrEmpty(emailValue))
            {
                // Try to get subscriber by email address
                sb = SubscriberInfoProvider.GetSubscriberInfo(emailValue, siteId);
            }
        }

        if ((sb == null) || (chooseMode && (sb != null)))
        {
            // Create subscriber
            if (sb == null)
            {
                if (formElem.Visible)
                {
                    // Specify SiteID for the new subscriber
                    formElem.Data.SetValue("SubscriberSiteID", siteId);

                    // Validate and save form with new subscriber data
                    if (!formElem.Save())
                    {
                        return(null);
                    }

                    // Get subscriber info from form
                    sb = (SubscriberInfo)formElem.Info;
                }
                else
                {
                    sb = new SubscriberInfo();
                }
            }

            // Handle authenticated user
            if (AllowUserSubscribers && isAuthenticated)
            {
                // Get user info and copy first name, last name or full name to new subscriber
                // if these properties were not set
                UserInfo ui = UserInfoProvider.GetUserInfo(CurrentUser.UserID);
                if (ui != null)
                {
                    if (!DataHelper.IsEmpty(ui.FirstName) && !DataHelper.IsEmpty(ui.LastName))
                    {
                        if (string.IsNullOrEmpty(sb.SubscriberFirstName))
                        {
                            sb.SubscriberFirstName = ui.FirstName;
                        }
                        if (string.IsNullOrEmpty(sb.SubscriberLastName))
                        {
                            sb.SubscriberLastName = ui.LastName;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(sb.SubscriberFirstName))
                        {
                            sb.SubscriberFirstName = ui.FullName;
                        }
                    }

                    // Full name consists of "user " and user full name
                    sb.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName);

                    if (!string.IsNullOrEmpty(sb.SubscriberEmail) && string.IsNullOrEmpty(ui.Email))
                    {
                        // Update user email if it was not set
                        ui.Email = sb.SubscriberEmail;
                        UserInfoProvider.SetUserInfo(ui);

                        // Reset email for user subscriber
                        sb.SubscriberEmail = null;
                    }
                }
                else
                {
                    return(null);
                }

                sb.SubscriberType      = UserInfo.OBJECT_TYPE;
                sb.SubscriberRelatedID = ui.UserID;
            }
            // Work with non-authenticated user
            else
            {
                if (string.IsNullOrEmpty(sb.SubscriberFullName))
                {
                    // Fill full name if it was not set via the form
                    sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim();
                }
            }

            // Set site ID
            sb.SubscriberSiteID = siteId;

            // Check subscriber limits
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                // Remove created subscriber and display error message
                SubscriberInfoProvider.DeleteSubscriberInfo(sb);

                lblError.Visible = true;
                lblError.Text    = GetString("LicenseVersionCheck.Subscribers");
                return(null);
            }

            // Update subscriber info
            SubscriberInfoProvider.SetSubscriberInfo(sb);
        }

        if (sb != null)
        {
            // Create membership between current contact and subscriber
            ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID());
        }

        // Return subscriber info object
        return(sb);
    }
コード例 #19
0
    /// <summary>
    /// Persona items selected event handler.
    /// </summary>
    protected void PersonaSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (personaSelector == null)
        {
            return;
        }

        int siteId = SiteContext.CurrentSiteID;

        // Get new items from selector
        string newValues = ValidationHelper.GetString(personaSelector.Value, null);

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Personas, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            // Get persona ID
            int personaID = ValidationHelper.GetInteger(item, 0);

            // Try to get subscriber
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.PERSONA, personaID, siteId);
            if (subscriber == null)
            {
                // Get persona display name
                var    persona     = BaseAbstractInfoProvider.GetInfoById(PredefinedObjectType.PERSONA, personaID);
                string personaName = ValidationHelper.GetString(persona.GetValue("PersonaDisplayName"), string.Empty);
                if (string.IsNullOrEmpty(personaName))
                {
                    continue;
                }

                // Create new subscriber of persona type
                subscriber = new SubscriberInfo();

                subscriber.SubscriberFirstName = personaName;

                // Full name consists of "persona" and display name
                subscriber.SubscriberFullName = new SubscriberFullNameFormater().GetPersonaSubscriberName(personaName);

                subscriber.SubscriberSiteID    = siteId;
                subscriber.SubscriberType      = PredefinedObjectType.PERSONA;
                subscriber.SubscriberRelatedID = personaID;

                CheckPermissionsForSubscriber(subscriber);

                SubscriberInfoProvider.SetSubscriberInfo(subscriber);
            }

            if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID))
            {
                mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings()
                {
                    SendConfirmationEmail = chkSendConfirmation.Checked,
                    RequireOptIn          = false,
                    RemoveAlsoUnsubscriptionFromAllNewsletters = false,
                });
            }
        }

        personaSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
コード例 #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get data from query string
        Guid   subscriberGuid   = QueryHelper.GetGuid("subscriberguid", Guid.Empty);
        Guid   newsletterGuid   = QueryHelper.GetGuid("newsletterguid", Guid.Empty);
        string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty);
        Guid   issueGuid        = QueryHelper.GetGuid("issueGuid", Guid.Empty);
        int    issueID          = QueryHelper.GetInteger("issueid", 0);
        int    contactId        = QueryHelper.GetInteger("contactid", 0);
        bool   unsubscribed     = false;

        string   requestTime = QueryHelper.GetString("datetime", string.Empty);
        DateTime datetime    = DateTimeHelper.ZERO_TIME;

        // Get date and time
        if (!string.IsNullOrEmpty(requestTime))
        {
            try
            {
                datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null);
            }
            catch
            {
                ShowError(GetString("newsletter.unsubscribefailed"));
                return;
            }
        }

        // Get site ID
        int siteId = 0;

        if (CMSContext.CurrentSite != null)
        {
            siteId = CMSContext.CurrentSiteID;
        }

        if ((subscriberGuid != Guid.Empty) && (newsletterGuid != Guid.Empty) && (siteId != 0))
        {
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberGuid, siteId);
            if (subscriber == null)
            {
                ShowError(GetString("Unsubscribe.SubscriberDoesNotExist"));
                return;
            }
            // Show error message if subscriber type is 'Role'
            if (!string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.EqualsCSafe(SiteObjectType.ROLE, true))
            {
                ShowError(GetString("Unsubscribe.CannotUnsubscribeRole"));
                return;
            }

            NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterGuid, siteId);
            if (newsletter == null)
            {
                ShowError(GetString("Unsubscribe.NewsletterDoesNotExist"));
                return;
            }

            // Check if subscriber with given GUID is subscribed to specified newsletter
            if (SubscriberInfoProvider.IsSubscribed(subscriber.SubscriberID, newsletter.NewsletterID))
            {
                bool isSubscribed = true;

                if (string.IsNullOrEmpty(subscriber.SubscriberType) || !subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true))
                {
                    // Unsubscribe action
                    SubscriberInfoProvider.Unsubscribe(subscriber.SubscriberID, newsletter.NewsletterID);
                }
                else
                {
                    // Check if the contact group member has unsubscription activity for the specified newsletter
                    isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, newsletter.NewsletterID, siteId);
                }

                if (isSubscribed)
                {
                    // Log newsletter unsubscription activity
                    LogActivity(subscriber, 0, newsletter.NewsletterID, issueID, contactId);

                    // Display confirmation
                    ShowInformation(GetString("Unsubscribe.Unsubscribed"));
                    unsubscribed = true;
                }
                else
                {
                    // Contact group member is already unsubscribed
                    ShowError(GetString("Unsubscribe.NotSubscribed"));
                }
            }
            else
            {
                ShowError(GetString("Unsubscribe.NotSubscribed"));
            }
        }
        // Check if subscription approval hash is supplied
        else if (!string.IsNullOrEmpty(subscriptionHash))
        {
            SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash);
            // Check if hash is valid
            if ((sni != null) && sni.SubscriptionEnabled)
            {
                SubscriberInfoProvider.ApprovalResult result = SubscriberInfoProvider.Unsubscribe(subscriptionHash, true, CMSContext.CurrentSiteName, datetime);

                switch (result)
                {
                // Approving subscription was successful
                case SubscriberInfoProvider.ApprovalResult.Success:
                    bool isSubscribed = true;

                    // Get subscriber
                    SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(sni.SubscriberID);
                    if ((subscriber != null) && !string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true))
                    {
                        // Check if the contact group member has unsubscription activity for the specified newsletter
                        isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, sni.NewsletterID, siteId);
                    }

                    if (isSubscribed)
                    {
                        // Log newsletter unsubscription activity
                        LogActivity(null, sni.SubscriberID, sni.NewsletterID, issueID, contactId);

                        // Display confirmation
                        ShowInformation(GetString("Unsubscribe.Unsubscribed"));
                        unsubscribed = true;
                    }
                    else
                    {
                        // Contact group member is already unsubscribed
                        ShowError(GetString("Unsubscribe.NotSubscribed"));
                    }
                    break;

                // Subscription was already approved
                case SubscriberInfoProvider.ApprovalResult.Failed:
                    ShowError(GetString("newsletter.unsubscribefailed"));
                    break;

                case SubscriberInfoProvider.ApprovalResult.TimeExceeded:
                    ShowError(GetString("newsletter.approval_timeexceeded"));
                    break;

                // Subscription not found
                default:
                case SubscriberInfoProvider.ApprovalResult.NotFound:
                    ShowError(GetString("Unsubscribe.NotSubscribed"));
                    break;
                }
            }
            else
            {
                ShowError(GetString("Unsubscribe.NotSubscribed"));
            }
        }
        else
        {
            if (subscriberGuid == Guid.Empty)
            {
                ShowError(GetString("Unsubscribe.SubscriberDoesNotExist"));
            }
            if (newsletterGuid == Guid.Empty)
            {
                ShowError(GetString("Unsubscribe.NewsletterDoesNotExist"));
            }
        }

        // Increase unsubscribed count
        if (unsubscribed)
        {
            // If Issue ID was provided
            if (issueID > 0)
            {
                IssueInfoProvider.Unsubscribe(issueID);
                return;
            }
            // Otherwise try using the Issue GUID
            if (issueGuid != Guid.Empty)
            {
                IssueInfo issue = IssueInfoProvider.GetIssueInfo(issueGuid, siteId);
                if (issue == null)
                {
                    return;
                }

                IssueInfoProvider.Unsubscribe(issue.IssueID);
            }
        }
    }
コード例 #21
0
    private void InitializeSubscriber(UserInfo user, int siteId)
    {
        var contact = mContactProvider.GetContactForSubscribing(user);

        subscriber = SubscriberInfoProvider.GetSubscriberInfo(ContactInfo.OBJECT_TYPE, contact.ContactID, siteId);
    }
コード例 #22
0
    /// <summary>
    /// Save subscriber.
    /// </summary>
    /// <returns>Subscriver info object</returns>
    private SubscriberInfo SaveSubscriber()
    {
        // Check if a subscriber exists first
        SubscriberInfo sb = null;

        if (AllowUserSubscribers && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated())
        {
            sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, MembershipContext.AuthenticatedUser.UserID, SiteContext.CurrentSiteID);
        }
        else
        {
            sb = SubscriberInfoProvider.GetSubscriberInfo(txtEmail.Text, SiteContext.CurrentSiteID);
        }

        if ((sb == null) || ((chooseMode) && (sb != null)))
        {
            // Create subscriber
            if (sb == null)
            {
                sb = new SubscriberInfo();
            }

            // Handle authenticated user
            if (AllowUserSubscribers && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated())
            {
                UserInfo ui = UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserID);

                var subscriberUserProvider = Service <ISubscriberUserProvider> .Entry();

                subscriberUserProvider.UpdateSubscriberForUser(sb, ui, SiteContext.CurrentSiteID);
            }
            // Work with non-authenticated user
            else
            {
                sb.SubscriberEmail = txtEmail.Text.Trim();

                // First name
                if (DisplayFirstName)
                {
                    sb.SubscriberFirstName = txtFirstName.Text;
                }
                else
                {
                    sb.SubscriberFirstName = string.Empty;
                }

                // Last name
                if (DisplayLastName)
                {
                    sb.SubscriberLastName = txtLastName.Text;
                }
                else
                {
                    sb.SubscriberLastName = string.Empty;
                }

                // Full name
                sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim();

                // Set site ID
                sb.SubscriberSiteID = SiteContext.CurrentSiteID;
            }


            // Check subscriber limits
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("LicenseVersionCheck.Subscribers");
                return(null);
            }

            // Save subscriber info
            SubscriberInfoProvider.SetSubscriberInfo(sb);
        }

        if (sb != null)
        {
            // Create membership between current contact and subscriber
            ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID());
        }

        // Hide all
        visibleLastName  = false;
        visibleFirstName = false;
        visibleEmail     = false;

        pnlButtonSubmit.Visible = false;
        pnlImageSubmit.Visible  = false;

        plcNwsList.Visible = false;

        // Clear the form
        txtEmail.Text     = string.Empty;
        txtFirstName.Text = string.Empty;
        txtLastName.Text  = string.Empty;

        // Return subscriber info object
        return(sb);
    }
コード例 #23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // If StopProcessing flag is set, do nothing
        if (StopProcessing)
        {
            Visible = false;
            return;
        }

        string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty);
        string requestTime      = QueryHelper.GetString("datetime", string.Empty);

        DateTime datetime = DateTimeHelper.ZERO_TIME;

        // Get date and time
        if (!string.IsNullOrEmpty(requestTime))
        {
            try
            {
                datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null);
            }
            catch
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_failed");
                return;
            }
        }

        if (string.IsNullOrEmpty(subscriptionHash))
        {
            Visible = false;
            return;
        }

        // Try to approve subscription
        SubscriberInfoProvider.ApprovalResult result = SubscriberInfoProvider.ApproveSubscription(subscriptionHash, false, CMSContext.CurrentSiteName, datetime);

        switch (result)
        {
        // Approving subscription was successful
        case SubscriberInfoProvider.ApprovalResult.Success:
            if (!String.IsNullOrEmpty(SuccessfulApprovalText))
            {
                lblInfo.Text = SuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.successful_approval");
            }

            // Log newsletter subscription activity
            SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash);
            if ((sni != null) && sni.SubscriptionEnabled)
            {
                NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(sni.NewsletterID);
                SubscriberInfo sb   = SubscriberInfoProvider.GetSubscriberInfo(sni.SubscriberID);
                if (sb != null)
                {
                    // Under what contacs this subscriber belogs to?
                    int contactId = ActivityTrackingHelper.GetContactID(sb);
                    if (contactId > 0)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
                        if (activity.Data != null)
                        {
                            activity.Data.ContactID = contactId;
                            activity.Log();
                        }
                    }
                }
            }
            break;

        // Subscription was already approved
        case SubscriberInfoProvider.ApprovalResult.Failed:
            if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
            {
                lblInfo.Text = UnsuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_failed");
            }
            break;

        case SubscriberInfoProvider.ApprovalResult.TimeExceeded:
            if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
            {
                lblInfo.Text = UnsuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_timeexceeded");
            }
            break;


        // Subscription not found
        default:
        case SubscriberInfoProvider.ApprovalResult.NotFound:
            if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
            {
                lblInfo.Text = UnsuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_invalid");
            }
            break;
        }
    }
コード例 #24
0
    /// <summary>
    /// Save subscriber.
    /// </summary>
    /// <returns>Subscriver info object</returns>
    private SubscriberInfo SaveSubscriber()
    {
        // Check if a subscriber exists first
        SubscriberInfo sb = null;

        if (AllowUserSubscribers && (CMSContext.CurrentUser != null) && CMSContext.CurrentUser.IsAuthenticated())
        {
            sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.USER, CMSContext.CurrentUser.UserID, CMSContext.CurrentSiteID);
        }
        else
        {
            sb = SubscriberInfoProvider.GetSubscriberInfo(txtEmail.Text, CMSContext.CurrentSiteID);
        }

        if ((sb == null) || ((chooseMode) && (sb != null)))
        {
            // Create subscriber
            if (sb == null)
            {
                sb = new SubscriberInfo();
            }

            // Handle authenticated user
            if (AllowUserSubscribers && (CMSContext.CurrentUser != null) && CMSContext.CurrentUser.IsAuthenticated())
            {
                // Get user info and copy first name, last name or full name to new subscriber
                UserInfo ui = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserID);
                if (ui != null)
                {
                    if (!DataHelper.IsEmpty(ui.FirstName) && !DataHelper.IsEmpty(ui.LastName))
                    {
                        sb.SubscriberFirstName = ui.FirstName;
                        sb.SubscriberLastName  = ui.LastName;
                    }
                    else
                    {
                        sb.SubscriberFirstName = ui.FullName;
                    }
                    // Full name consists of "user " and user full name
                    sb.SubscriberFullName = "User '" + ui.FullName + "'";
                }
                else
                {
                    return(null);
                }

                sb.SubscriberType      = PredefinedObjectType.USER;
                sb.SubscriberRelatedID = CMSContext.CurrentUser.UserID;
            }
            // Work with non-authenticated user
            else
            {
                sb.SubscriberEmail = txtEmail.Text.Trim();

                // First name
                if (DisplayFirstName)
                {
                    sb.SubscriberFirstName = txtFirstName.Text;
                }
                else
                {
                    sb.SubscriberFirstName = string.Empty;
                }

                // Last name
                if (DisplayLastName)
                {
                    sb.SubscriberLastName = txtLastName.Text;
                }
                else
                {
                    sb.SubscriberLastName = string.Empty;
                }

                // Full name
                sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim();
            }

            // Set site ID
            sb.SubscriberSiteID = CMSContext.CurrentSiteID;

            // Check subscriber limits
            if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("LicenseVersionCheck.Subscribers");
                return(null);
            }

            // Save subscriber info
            SubscriberInfoProvider.SetSubscriberInfo(sb);
        }

        if (sb != null)
        {
            // Create membership between current contact and subscriber
            ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID());
        }

        // Hide all
        visibleLastName  = false;
        visibleFirstName = false;
        visibleEmail     = false;

        pnlButtonSubmit.Visible = false;
        pnlImageSubmit.Visible  = false;

        plcNwsList.Visible = false;

        // Clear the form
        txtEmail.Text     = string.Empty;
        txtFirstName.Text = string.Empty;
        txtLastName.Text  = string.Empty;

        // Return subscriber info object
        return(sb);
    }