Exemple #1
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));
        }
        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));
        }
        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) && !DateTime.TryParseExact(model.DateTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null, System.Globalization.DateTimeStyles.None, out parsedDateTime))
            {
                ModelState.AddModelError(String.Empty, ResHelper.GetString("DancingGoatMvc.News.ConfirmSubscriptionInvalidDateTime"));

                return(View(model));
            }

            var result = mSubscriptionService.ConfirmSubscription(model.SubscriptionHash, false, 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));
        }