Exemple #1
0
        //EndDocSection:Constructor

        //DocSection:DisplayConsent
        public ActionResult DisplayConsent()
        {
            // Gets the related tracking consent
            // Fill in the code name of the appropriate consent object in Kentico
            ConsentInfo consent = ConsentInfoProvider.GetConsentInfo("SampleTrackingConsent");

            // Gets the current contact
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact();

            // Sets the default cookie level for contacts who have revoked the tracking consent
            // Required for scenarios where one contact uses multiple browsers
            if ((currentContact != null) && !consentAgreementService.IsAgreed(currentContact, consent))
            {
                var defaultCookieLevel = currentCookieLevelProvider.GetDefaultCookieLevel();
                currentCookieLevelProvider.SetCurrentCookieLevel(defaultCookieLevel);
            }

            var consentModel = new TrackingConsentViewModel
            {
                // Adds the consent's short text to the model
                ShortText = consent.GetConsentText("en-US").ShortText,

                // Checks whether the current contact has given an agreement for the tracking consent
                IsAgreed = (currentContact != null) && consentAgreementService.IsAgreed(currentContact, consent)
            };

            return(View("Consent", consentModel));
        }
    private void UseDefaultCookieLevelWhenConsentIsNotAgreed()
    {
        var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsent);
        var contact = ContactManagementContext.CurrentContact;

        if (consent != null && contact != null)
        {
            if (!Service.Resolve <IConsentAgreementService>().IsAgreed(contact, consent))
            {
                cookieLevelProvider.SetCurrentCookieLevel(cookieLevelProvider.GetDefaultCookieLevel());
            }
        }
    }
Exemple #3
0
        public ActionResult Agree()
        {
            var resultStatus = HttpStatusCode.BadRequest;

            var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsentGenerator.CONSENT_NAME);

            if (consent != null)
            {
                mCookieLevelProvider.SetCurrentCookieLevel(CookieLevel.All);
                mConsentAgreementService.Agree(ContactManagementContext.CurrentContact, consent);

                resultStatus = HttpStatusCode.OK;
            }

            // Redirect is handled on client by javascript
            return(new HttpStatusCodeResult(resultStatus));
        }
Exemple #4
0
        public ActionResult Revoke(int consentId)
        {
            // Gets the related consent object
            ConsentInfo consent = ConsentInfoProvider.GetConsentInfo(consentId);

            // Gets the current visitor's contact
            ContactInfo currentContact = contactTrackingService.GetCurrentContactAsync(User.Identity.Name).Result;

            // For the tracking consent, lowers the cookie level to the site's default in order to disable tracking
            if (consent.ConsentName == "SampleTrackingConsent")
            {
                currentCookieLevelProvider.SetCurrentCookieLevel(currentCookieLevelProvider.GetDefaultCookieLevel());
            }

            // Revokes the consent agreement
            consentAgreementService.Revoke(currentContact, consent);

            return(RedirectToAction("Index"));
        }
Exemple #5
0
        public ActionResult Agree(string returnUrl)
        {
            var consent = consentInfoProvider.Get(TrackingConsentGenerator.CONSENT_NAME);

            if (consent != null)
            {
                cookieLevelProvider.SetCurrentCookieLevel(CookieLevel.All);

                var contact = ContactManagementContext.CurrentContact;
                if (contact != null)
                {
                    consentAgreementService.Agree(contact, consent);
                }

                return(Redirect(returnUrl));
            }

            return(new StatusCodeResult(StatusCodes.Status400BadRequest));
        }
Exemple #6
0
        public ActionResult Revoke(string consentName)
        {
            var consentToRevoke = consentInfoProvider.Get(consentName);

            if (consentToRevoke != null && CurrentContact != null)
            {
                consentAgreementService.Revoke(CurrentContact, consentToRevoke);

                if (consentName == TrackingConsentGenerator.CONSENT_NAME)
                {
                    cookieLevelProvider.SetCurrentCookieLevel(cookieLevelProvider.GetDefaultCookieLevel());
                    ExecuteRevokeTrackingConsentTask(siteService.CurrentSite, CurrentContact);
                }

                TempData[SUCCESS_RESULT] = true;
            }
            else
            {
                TempData[ERROR_RESULT] = true;
            }

            return(Redirect(Url.Kentico().PageUrl(ContentItemIdentifiers.PRIVACY)));
        }
        public ActionResult Revoke(string consentName)
        {
            var consentToRevoke = ConsentInfoProvider.GetConsentInfo(consentName);

            if (consentToRevoke != null && CurrentContact != null)
            {
                mConsentAgreementService.Revoke(CurrentContact, consentToRevoke);

                if (consentName == TrackingConsentGenerator.CONSENT_NAME)
                {
                    mCookieLevelProvider.SetCurrentCookieLevel(mCookieLevelProvider.GetDefaultCookieLevel());
                    ExecuteRevokeTrackingConsentTask(mSiteService.CurrentSite, CurrentContact);
                }

                TempData[SUCCESS_RESULT] = true;
            }
            else
            {
                TempData[ERROR_RESULT] = true;
            }

            return(RedirectToAction("Index"));
        }