예제 #1
0
        public OptInResponseModel OptIn(string publicationName)
        {
            var page = _dependencies.SitecoreContext.GetCurrentItem <ISubscribe_Page>();

            var responseModel = new OptInResponseModel
            {
                BodyText        = page.Body.Replace("#USER_EMAIL#", _dependencies.AuthenticatedUserContext?.User?.Username ?? string.Empty),
                IsAuthenticated = _dependencies.AuthenticatedUserContext?.IsAuthenticated ?? false,
                SignInViewModel = _dependencies.SignInViewModel
            };

            if (!responseModel.IsAuthenticated)
            {
                //redirect to email preferences
                var url = page._Parent?._Url ?? string.Empty;
                if (!string.IsNullOrEmpty(url))
                {
                    responseModel.RedirectUrl = url;
                }
                return(responseModel);
            }

            var isCurrentPublication = !string.IsNullOrEmpty(publicationName) &&
                                       (string.Equals(publicationName, _dependencies.SitePublicationNameContext.Name,
                                                      StringComparison.CurrentCultureIgnoreCase));

            if (isCurrentPublication)
            {
                var userOptIn = _dependencies.NewsletterUserOptInFactory.Create(_dependencies.SitePublicationNameContext.Name, true);
                _dependencies.UpdateNewsletterUserOptInsContext.Update(new[] { userOptIn });
            }

            return(responseModel);
        }
 private void PopulatePropertiesFromResponse(OptInResponseModel response)
 {
     IsOptOutSuccessful = response.IsSuccessful;
     if (IsOptOutSuccessful)
     {
         HeaderText      = _dependencies.TextTranslator.Translate("Account.SavedSearches.OptOutHeader");
         SavedSearchName = response.BodyText;
         BodyText        = GlassModel?.Body.Replace(SavedSearchNameToken, SavedSearchName);
     }
     else
     {
         HeaderText = _dependencies.TextTranslator.Translate("Account.SavedSearches.OptOutFailed");
         BodyText   = string.Empty;
     }
 }
예제 #3
0
        public OptInResponseModel OptOut(string userName, string type, string publicationName)
        {
            var page = _dependencies.SitecoreContext.GetCurrentItem <IUnsubscribe_Page>();

            var responseModel = new OptInResponseModel
            {
                BodyText        = page.Body,
                SignInViewModel = _dependencies.SignInViewModel
            };

            if (string.IsNullOrEmpty(type))
            {
                return(responseModel);
            }

            //process unsubscribe
            var newsletterType = _dependencies.SitePublicationNameContext.Name;

            if (type.ToLower() == "newsletter" && !string.IsNullOrEmpty(publicationName) && (publicationName.ToLower() == newsletterType.ToLower()))
            {
                if (_dependencies.AuthenticatedUserContext.IsAuthenticated)
                {
                    var userOptIn = _dependencies.NewsletterUserOptInFactory.Create(_dependencies.SitePublicationNameContext.Name, false);
                    _dependencies.UpdateNewsletterUserOptInsContext.Update(new[] { userOptIn });
                }
                else if (!string.IsNullOrWhiteSpace(userName))
                {
                    _dependencies.UpdateSiteNewsletterUserOptIn.Update(userName, false);
                }
            }
            else if (type.ToLower() == "promotions")
            {
                if (responseModel.IsAuthenticated)
                {
                    _dependencies.UpdateOfferUserOptInContext.Update(false);
                }
                else if (!string.IsNullOrWhiteSpace(userName))
                {
                    _dependencies.UpdateOfferUserOptIn.Update(userName, false);
                }
            }

            return(responseModel);
        }
예제 #4
0
        public OptInResponseModel AnnonymousOptOut(string token)
        {
            var entity   = ParseToken(token);
            var response = new OptInResponseModel {
                IsAuthenticated = false
            };

            response.IsSuccessful = entity != null &&
                                    _dependencies.SavedSearchEntityRepository.Delete(entity).Success;

            if (response.IsSuccessful)
            {
                response.BodyText = entity.Name;
            }

            if (_dependencies.AuthenticatedUserContext.IsAuthenticated)
            {
                _dependencies.AuthenticatedUserSession.Clear(SavedSearchService.SessionKey);
            }

            return(response);
        }