/// <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;
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Handles multiple selector actions.
    /// </summary>
    protected void btnOk_Clicked(object sender, EventArgs e)
    {
        // Check permissions
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "ManageSubscribers"))
        {
            RedirectToCMSDeskAccessDenied("cms.newsletter", "ManageSubscribers");
        }
        // Return if no action was selected
        if (drpActions.SelectedValue.Equals("SELECT", StringComparison.InvariantCultureIgnoreCase))
        {
            return;
        }

        // Get selected items
        ArrayList list = unigridNewsletters.SelectedItems;

        if (list.Count == 0)
        {
            ltlScript.Text += ScriptHelper.GetAlertScript(GetString("general.noitems"));
            return;
        }

        int newsletterId;
        SubscriberNewsletterInfo subscriptionInfo;

        foreach (object id in list)
        {
            newsletterId = ValidationHelper.GetInteger(id, 0);

            switch (drpActions.SelectedValue)
            {
            // Remove subscription
            case "REMOVE":
                SubscriberProvider.Unsubscribe(subscriberId, newsletterId, chkSendConfirmation.Checked);
                break;

            // Approve subscription
            case "APPROVE":
                subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
                if ((subscriptionInfo != null) && (!subscriptionInfo.SubscriptionApproved))
                {
                    subscriptionInfo.SubscriptionApproved     = true;
                    subscriptionInfo.SubscriptionApprovedWhen = DateTime.Now;
                    SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
                }
                break;

            // Reject subscription
            case "REJECT":
                subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
                if ((subscriptionInfo != null) && (subscriptionInfo.SubscriptionApproved))
                {
                    subscriptionInfo.SubscriptionApproved     = false;
                    subscriptionInfo.SubscriptionApprovedWhen = DateTime.MinValue;
                    SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
                }
                break;
            }
        }

        unigridNewsletters.ResetSelection();
        unigridNewsletters.ReloadData();
    }
Exemple #3
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))
        {
            Subscriber subscriber = SubscriberProvider.GetSubscriber(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.Equals(SiteObjectType.ROLE, StringComparison.InvariantCultureIgnoreCase))
            {
                ShowError(GetString("Unsubscribe.CannotUnsubscribeRole"));
                return;
            }

            Newsletter newsletter = NewsletterProvider.GetNewsletter(newsletterGuid, siteId);
            if (newsletter == null)
            {
                ShowError(GetString("Unsubscribe.NewsletterDoesNotExist"));
                return;
            }

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

                if (string.IsNullOrEmpty(subscriber.SubscriberType) || !subscriber.SubscriberType.Equals(PredefinedObjectType.CONTACTGROUP, StringComparison.InvariantCultureIgnoreCase))
                {
                    // Unsubscribe action
                    SubscriberProvider.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, issueGuid, siteId, 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)
            {
                SubscriberProvider.ApprovalResult result = SubscriberProvider.Unsubscribe(subscriptionHash, true, CMSContext.CurrentSiteName, datetime);

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

                    // Get subscriber
                    Subscriber subscriber = SubscriberProvider.GetSubscriber(sni.SubscriberID);
                    if ((subscriber != null) && !string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.Equals(PredefinedObjectType.CONTACTGROUP, StringComparison.InvariantCultureIgnoreCase))
                    {
                        // 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, issueGuid, siteId, 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 SubscriberProvider.ApprovalResult.Failed:
                    ShowError(GetString("newsletter.unsubscribefailed"));
                    break;

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

                // Subscription not found
                default:
                case SubscriberProvider.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)
            {
                IssueProvider.Unsubscribe(issueID);
                return;
            }
            // Otherwise try using the Issue GUID
            if (issueGuid != Guid.Empty)
            {
                Issue issue = IssueProvider.GetIssue(issueGuid, siteId);
                if (issue == null)
                {
                    return;
                }

                IssueProvider.Unsubscribe(issue.IssueID);
            }
        }
    }
Exemple #4
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // Check email format
        string email  = txtEmail.Text.Trim();
        string result = new Validator().IsEmail(email, GetString("unsubscribe.invalidemailformat")).Result;

        if (String.IsNullOrEmpty(result))
        {
            bool requestSent = false;
            int  siteId      = 0;
            if (CMSContext.CurrentSite != null)
            {
                siteId = CMSContext.CurrentSiteID;
            }

            // Try to get all subscriber infos with given e-mail
            DataSet ds = SubscriberProvider.GetSubscribersFromView(email, siteId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Subscriber sb = new Subscriber(dr);
                    if ((sb != null) && ((sb.SubscriberType == null) || (sb.SubscriberRelatedID > 0) && (sb.SubscriberType == SiteObjectType.USER)))
                    {
                        // Get newsletter information
                        Newsletter news = NewsletterProvider.GetNewsletter(this.NewsletterName, siteId);
                        if (news != null)
                        {
                            // Get subscription info
                            SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(sb.SubscriberID, news.NewsletterID);
                            // Send e-mail to subscribed user only
                            if (sni != null)
                            {
                                SendUnsubscriptionRequest(sb, news, sni, CMSContext.CurrentSiteName);
                                requestSent = true;  // At least one request was sent
                            }
                        }
                    }
                }
            }

            // Unsubscription failed if none confirmation e-mail was sent
            if (!requestSent)
            {
                // Use default error message if none is specified
                if (String.IsNullOrEmpty(this.ErrorText))
                {
                    result = GetString("unsubscribe.notsubscribed");
                }
                else
                {
                    result = this.ErrorText;
                }
            }
        }

        // Display error message if set
        if (!string.IsNullOrEmpty(result))
        {
            lblError.Text    = result;
            lblError.Visible = true;
        }
        else
        {
            // Display unsubscription confirmation
            lblInfo.Visible = true;
            if (String.IsNullOrEmpty(this.ResultText))
            {
                // Use default message if none was specified
                lblInfo.Text = GetString("unsubscribe.confirmtext");
            }
            else
            {
                lblInfo.Text = this.ResultText;
            }
            lblError.Visible  = false;
            txtEmail.Visible  = false;
            btnSubmit.Visible = false;
        }
    }
    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;
        }
    }
    /// <summary>
    /// Handles multiple selector actions.
    /// </summary>
    protected void btnOk_Clicked(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (drpActions.SelectedValue != SELECT)
        {
            // Go through all selected items
            List <string> list = UniGridSubscribers.SelectedItems;
            if (list.Count > 0)
            {
                foreach (string subscriberId in list)
                {
                    var subscriberInt = ValidationHelper.GetInteger(subscriberId, 0);
                    var sni           = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberInt, newsletterId);
                    if (sni != null)
                    {
                        switch (drpActions.SelectedValue)
                        {
                        // Subscribe
                        case SUBSCRIBE:
                            SubscriberInfoProvider.RenewSubscription(subscriberInt, newsletterId, chkSendConfirmation.Checked);
                            break;

                        // Unsubscribe
                        case UNSUBSCRIBE:
                            SubscriberInfoProvider.Unsubscribe(sni, chkSendConfirmation.Checked);
                            break;

                        // Remove subscription
                        case REMOVE:
                            SubscriberInfoProvider.DeleteSubscription(subscriberInt, newsletterId, chkSendConfirmation.Checked);
                            break;

                        // Approve subscription
                        case APPROVE:
                            if (!sni.SubscriptionApproved)
                            {
                                sni.SubscriptionApproved     = true;
                                sni.SubscriptionApprovedWhen = DateTime.Now;
                                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(sni);
                            }
                            break;

                        // Reject subscription
                        case REJECT:
                            if (sni.SubscriptionApproved)
                            {
                                sni.SubscriptionApproved     = false;
                                sni.SubscriptionApprovedWhen = DateTime.MinValue;
                                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(sni);
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                ltlScript.Text += ScriptHelper.GetAlertScript(GetString("general.noitems"));
            }
        }
        UniGridSubscribers.ResetSelection();
        UniGridSubscribers.ReloadData();
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void UniGridSubscribers_OnAction(string actionName, object actionArgument)
    {
        // Check 'manage subscribers' permission
        CheckAuthorization();

        int subscriberId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLowerCSafe())
        {
        // Renew subscription
        case "subscribe":
            SubscriberInfoProvider.RenewSubscription(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Unsubscribe selected subscriber
        case "unsubscribe":
            SubscriberInfoProvider.Unsubscribe(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Delete subscription
        case "remove":
            SubscriberInfoProvider.DeleteSubscription(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Approve selected subscription
        case "approve":
        {
            SubscriberNewsletterInfo subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
            if ((subscriptionInfo != null) && (!subscriptionInfo.SubscriptionApproved))
            {
                subscriptionInfo.SubscriptionApproved     = true;
                subscriptionInfo.SubscriptionApprovedWhen = DateTime.Now;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
            }
        }
        break;

        // Reject selected subscription
        case "reject":
        {
            SubscriberNewsletterInfo subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
            if ((subscriptionInfo != null) && (subscriptionInfo.SubscriptionApproved))
            {
                subscriptionInfo.SubscriptionApproved     = false;
                subscriptionInfo.SubscriptionApprovedWhen = DateTime.MinValue;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
            }
        }
        break;

        // Block selected subscriber
        case "block":
            SubscriberInfoProvider.BlockSubscriber(subscriberId);
            break;

        // Un-block selected subscriber
        case "unblock":
            SubscriberInfoProvider.UnblockSubscriber(subscriberId);
            break;
        }
    }
Exemple #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;
        }

        // 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;
        }
    }