//EndDocSection:Unsubscribe


        //DocSection:ConfirmSubscription
        /// <summary>
        /// Handles confirmation requests for newsletter subscriptions (when using double opt-in).
        /// </summary>
        public IActionResult ConfirmSubscription(NewsletterSubscriptionConfirmationViewModel model)
        {
            // Verifies that the confirmation request contains the required hash parameter
            if (!ModelState.IsValid)
            {
                // If the hash is missing, returns a view informing the user that the subscription confirmation was not successful
                ModelState.AddModelError(String.Empty, "The confirmation link is invalid.");
                return(View(model));
            }

            // Attempts to parse the date and time parameter from the request query string
            // Uses the date and time formats required by the Xperience API
            DateTime parsedDateTime = DateTimeHelper.ZERO_TIME;

            if (!string.IsNullOrEmpty(model.DateTime) && !DateTimeUrlFormatter.TryParse(model.DateTime, out parsedDateTime))
            {
                // Returns a view informing the user that the subscription confirmation was not successful
                ModelState.AddModelError(String.Empty, "The confirmation link is invalid.");
                return(View(model));
            }

            // Attempts to confirm the subscription specified by the request's parameters
            ApprovalResult result = subscriptionApprovalService.ApproveSubscription(model.SubscriptionHash, false, siteService.CurrentSite.SiteName, parsedDateTime);

            switch (result)
            {
            // The confirmation was successful or the recipient was already approved
            // Displays a view informing the user that the subscription is active
            case ApprovalResult.Success:
            case ApprovalResult.AlreadyApproved:
                return(View(model));

            // The confirmation link has expired
            // Expiration occurs after a certain number of hours from the time of the original subscription
            // You can set the expiration interval in Xperience (Settings -> On‑line marketing -> Email marketing -> Double opt-in interval)
            case ApprovalResult.TimeExceeded:
                ModelState.AddModelError(String.Empty, "Your confirmation link has expired. Please subscribe to the newsletter again.");
                break;

            // The subscription specified in the request's parameters does not exist
            case ApprovalResult.NotFound:
                ModelState.AddModelError(String.Empty, "The subscription that you are attempting to confirm does not exist.");
                break;

            // The confirmation failed
            default:
                ModelState.AddModelError(String.Empty, "The confirmation of your newsletter subscription did not succeed.");
                break;
            }

            // If the subscription confirmation was not successful, displays a view informing the user
            return(View(model));
        }
        public ActionResult ConfirmSubscription(ConfirmSubscriptionModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(String.Empty, ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionInvalidLink"));

                return(View(model));
            }

            DateTime parsedDateTime = DateTimeHelper.ZERO_TIME;

            // Parse date and time from query string, if present
            if (!string.IsNullOrEmpty(model.DateTime) && !DateTimeUrlFormatter.TryParse(model.DateTime, out parsedDateTime))
            {
                ModelState.AddModelError(String.Empty, ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionInvalidDateTime"));

                return(View(model));
            }

            var result = mSubscriptionApprovalService.ApproveSubscription(model.SubscriptionHash, false, SiteContext.CurrentSiteName, parsedDateTime);

            switch (result)
            {
            case ApprovalResult.Success:
                model.ConfirmationResult = ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionSucceeded");
                break;

            case ApprovalResult.AlreadyApproved:
                model.ConfirmationResult = ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionAlreadyConfirmed");
                break;

            case ApprovalResult.TimeExceeded:
                ModelState.AddModelError(String.Empty, ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionTimeExceeded"));
                break;

            case ApprovalResult.NotFound:
                ModelState.AddModelError(String.Empty, ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionInvalidLink"));
                break;

            default:
                ModelState.AddModelError(String.Empty, ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionFailed"));

                break;
            }

            return(View(model));
        }
Exemplo n.º 3
0
        // GET: Subscription/ConfirmSubscription
        public ActionResult ConfirmSubscription(ConfirmSubscriptionModel model)
        {
            if (!ModelState.IsValid)
            {
                AddError("The confirmation link is not valid.");

                return(View(model));
            }

            DateTime parsedDateTime = DateTimeHelper.ZERO_TIME;

            // Parse date and time from query string, if present
            if (!string.IsNullOrEmpty(model.DateTime) && !DateTimeUrlFormatter.TryParse(model.DateTime, out parsedDateTime))
            {
                AddError("The confirmation link is not valid.");

                return(View(model));
            }

            var result = subscriptionApprovalService.ApproveSubscription(model.SubscriptionHash, false, SiteContext.CurrentSiteName, parsedDateTime);

            switch (result)
            {
            case ApprovalResult.Success:
                model.ConfirmationResult = localizer["Your subscription has been confirmed."].Value;
                break;

            case ApprovalResult.AlreadyApproved:
                model.ConfirmationResult = localizer["You are already subscribed."].Value;
                break;

            case ApprovalResult.TimeExceeded:
                AddError("Your subscription confirmation link has expired. Please subscribe again.");
                break;

            case ApprovalResult.NotFound:
                AddError("The confirmation link is not valid.");
                break;

            default:
                AddError("The subscription confirmation has failed. Please try again later.");

                break;
            }

            return(View(model));
        }