コード例 #1
0
            public void ConfirmSubscription_Hash_DateTime_SubscriptionIsConfirmed()
            {
                var email    = "a-guid-" + Guid.NewGuid() + "@domain.com";
                var dateTime = DateTime.Now;
                var contact  = GetContact(email);

                mNewsletterSubscriptionService.Subscribe(contact, mNewsletter, mNewsletterSubscriptionSettings);

                // Get the expected subscriber and binding to newsletter so that hash for their subscription confirmation can be faked
                // (the newsletters API allows to retrieve current hash, but not the corresponding timestamp which is necessary to pass the validation).
                var expectedSubscriber = SubscriberInfoProvider.GetSubscriberByEmail(email, mSite.SiteID);
                var confirmationHash   = SecurityHelper.GenerateConfirmationEmailHash(mNewsletter.NewsletterGUID + "|" + expectedSubscriber.SubscriberGUID, dateTime);

                var expectedSubscriberNewsletter = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(expectedSubscriber.SubscriberID, mNewsletter.NewsletterID);

                expectedSubscriberNewsletter.SubscriptionApprovalHash = confirmationHash;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(expectedSubscriberNewsletter);

                var approvalResult = mNewsletterSubscriptionService.ConfirmSubscription(expectedSubscriberNewsletter.SubscriptionApprovalHash, false, dateTime);

                // Retrieve the subscriber-newsletter binding again so that approval state can be validated
                expectedSubscriberNewsletter = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(expectedSubscriber.SubscriberID, mNewsletter.NewsletterID);

                Assert.AreEqual(ApprovalResult.Success, approvalResult, "Subscription confirmation was not successful.");
                Assert.IsTrue(expectedSubscriberNewsletter.SubscriptionApproved, $"Subscription is not approved after confirmation.");
            }
 private void AssignSubscriberToNewsletter(int newsletterId, SubscriberInfo subscriber)
 {
     SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(new SubscriberNewsletterInfo
     {
         SubscriberID         = subscriber.SubscriberID,
         NewsletterID         = newsletterId,
         SubscriptionApproved = true,
         SubscribedWhen       = DateTime.Now
     });
 }
コード例 #3
0
    /// <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
            ArrayList list = UniGridSubscribers.SelectedItems;
            if (list.Count > 0)
            {
                SubscriberNewsletterInfo sni = null;
                foreach (object subscriberId in list)
                {
                    sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(ValidationHelper.GetInteger(subscriberId, 0), newsletterId);
                    if (sni != null)
                    {
                        switch (drpActions.SelectedValue)
                        {
                        // Remove subscription
                        case "REMOVE":
                            SubscriberProvider.Unsubscribe(sni, 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();
    }
コード例 #4
0
    /// <summary>
    /// Unigrid newsletters action handler.
    /// </summary>
    protected void unigridNewsletters_OnAction(string actionName, object actionArgument)
    {
        // Check 'configure' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "ManageSubscribers"))
        {
            RedirectToCMSDeskAccessDenied("cms.newsletter", "ManageSubscribers");
        }

        int newsletterId = 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;

        // Unsubscribe selected subscriber
        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;
        }
    }
コード例 #5
0
    /// <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.ToLower())
        {
        // Unsubscribe selected subscriber
        case "remove":
            SubscriberProvider.Unsubscribe(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":
            SubscriberProvider.BlockSubscriber(subscriberId);
            break;

        // Un-block selected subscriber
        case "unblock":
            SubscriberProvider.UnblockSubscriber(subscriberId);
            break;
        }
    }
コード例 #6
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.EqualsCSafe(SELECT, true))
        {
            return;
        }

        // Get selected items
        List <string> list = unigridNewsletters.SelectedItems;

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

        int newsletterId;
        SubscriberNewsletterInfo subscriptionInfo;

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

            switch (drpActions.SelectedValue)
            {
            // Subscribe
            case SUBSCRIBE:
                SubscriberInfoProvider.RenewSubscription(subscriberId, newsletterId, chkSendConfirmation.Checked);
                break;

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


            // Remove subscription
            case "REMOVE":
                SubscriberInfoProvider.DeleteSubscription(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();
    }