コード例 #1
0
    private void Form_OnBeforeSave(object sender, EventArgs e)
    {
        var info = Form.Data as BaseInfo;

        if (info == null)
        {
            return;
        }

        var service = Service.Resolve <IFormConsentAgreementService>();
        var consent = ConsentInfoProvider.GetConsentInfo(SelectedConsent);
        var contact = ContactManagementContext.GetCurrentContact();
        ConsentAgreementInfo agreement;

        if (chkConsent.Checked)
        {
            agreement = service.Agree(contact, consent, info);
        }
        else
        {
            agreement = service.Revoke(contact, consent, info);
        }

        StoreAgreementGuidInData(info, agreement);
    }
コード例 #2
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));
        }
コード例 #3
0
    private string GetConsentText()
    {
        var consent        = ConsentInfoProvider.GetConsentInfo(SelectedConsent);
        var currentCulture = LocalizationContext.CurrentCulture.CultureCode;

        return(consent != null?consent.GetConsentText(currentCulture).ShortText : string.Empty);
    }
コード例 #4
0
        /// <summary>
        /// Constructor.
        /// You can use a dependency injection container to initialize the consent agreement service.
        /// </summary>
        public RegisterWithConsentController()
        {
            formConsentAgreementService = Service.Resolve <IFormConsentAgreementService>();

            // Gets the related consent
            // Fill in the code name of the appropriate consent object in Kentico
            consent = ConsentInfoProvider.GetConsentInfo("SampleRegistrationConsent");
        }
コード例 #5
0
        /// <summary>
        /// Constructor.
        /// You can use a dependency injection container to initialize the services.
        /// </summary>
        public FeedbackFormConsentController()
        {
            contactTrackingService      = new ContactTrackingService();
            formConsentAgreementService = Service.Resolve <IFormConsentAgreementService>();

            // Gets the related consent
            // Fill in the code name of the appropriate consent object in Kentico
            consent = ConsentInfoProvider.GetConsentInfo("SampleFormConsent");
        }
コード例 #6
0
ファイル: CookieLaw.ascx.cs プロジェクト: shawchand/Kentico11
    private void RevokeConsent(ContactInfo contact)
    {
        var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsent);

        if ((consent != null) && contact != null)
        {
            Service.Resolve <IConsentAgreementService>().Revoke(contact, consent);
        }
    }
コード例 #7
0
ファイル: CookieLaw.ascx.cs プロジェクト: shawchand/Kentico11
    private void AgreeConsent()
    {
        var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsent);

        if ((consent != null) && (ContactManagementContext.CurrentContact != null))
        {
            Service.Resolve <IConsentAgreementService>().Agree(ContactManagementContext.CurrentContact, consent);
        }
    }
コード例 #8
0
ファイル: CookieLaw.ascx.cs プロジェクト: shawchand/Kentico11
    private void DisplayTrackingConsent()
    {
        var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsent);

        if (consent != null)
        {
            var cultureCode = LocalizationContext.CurrentCulture.CultureCode;
            ltlTrackingConsentShortText.Text = consent.GetConsentText(cultureCode).ShortText;
            pnlTrackingConsent.Visible       = true;
        }
    }
コード例 #9
0
ファイル: CookieLaw.ascx.cs プロジェクト: shawchand/Kentico11
    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());
            }
        }
    }
コード例 #10
0
        public ActionResult Accept()
        {
            // Gets the related tracking consent
            ConsentInfo consent = ConsentInfoProvider.GetConsentInfo("SampleTrackingConsent");

            // Sets the visitor's cookie level to 'All' (enables contact tracking)
            currentCookieLevelProvider.SetCurrentCookieLevel(CookieLevel.All);

            // Gets the current contact and creates a consent agreement
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact();

            consentAgreementService.Agree(currentContact, consent);

            return(RedirectToAction("DisplayConsent"));
        }
    protected void btnRevoke_Click(object sender, EventArgs e)
    {
        if (PortalContext.ViewMode.IsLiveSite())
        {
            Button      btn       = (Button)sender;
            int         consentId = ValidationHelper.GetInteger(btn.CommandArgument, 0);
            ConsentInfo consent   = ConsentInfoProvider.GetConsentInfo(consentId);

            if ((consent != null) && (CurrentContact != null))
            {
                ConsentAgreementService.Revoke(CurrentContact, consent);
                SetupControl();
                lblInfo.Visible = true;
            }
        }
    }
コード例 #12
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));
        }
コード例 #13
0
        public ActionResult Revoke()
        {
            // Gets the related tracking consent
            ConsentInfo consent = ConsentInfoProvider.GetConsentInfo("SampleTrackingConsent");

            // Gets the current contact and revokes the tracking consent agreement
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact();

            consentAgreementService.Revoke(currentContact, consent);

            // Sets the visitor's cookie level to the site's default cookie level (disables contact tracking)
            int defaultCookieLevel = currentCookieLevelProvider.GetDefaultCookieLevel();

            currentCookieLevelProvider.SetCurrentCookieLevel(defaultCookieLevel);

            return(RedirectToAction("DisplayConsent"));
        }
コード例 #14
0
        private void CreateConsent()
        {
            if (ConsentInfoProvider.GetConsentInfo(CONSENT_NAME) != null)
            {
                return;
            }

            var consent = new ConsentInfo
            {
                ConsentName        = CONSENT_NAME,
                ConsentDisplayName = CONSENT_DISPLAY_NAME,
            };

            consent.UpsertConsentText("en-US", CONSENT_SHORT_TEXT_EN, CONSENT_LONG_TEXT_EN);
            consent.UpsertConsentText("es-ES", CONSENT_SHORT_TEXT_ES, CONSENT_LONG_TEXT_ES);

            ConsentInfoProvider.SetConsentInfo(consent);
        }
コード例 #15
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"));
        }
コード例 #16
0
        public override bool Evaluate()
        {
            // Gets the contact object of the current visitor
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact(false);

            // Creates an instance of the consent agreement service
            // For real-world projects, we recommend using a dependency injection container to initialize service instances
            var consentAgreementService = Service.Resolve <IConsentAgreementService>();

            // Gets the consent object based on its code name
            ConsentInfo consent = ConsentInfoProvider.GetConsentInfo(ConsentCodeName);

            if (consent == null || currentContact == null)
            {
                return(false);
            }

            // Checks if the contact has given a consent agreement
            return(consentAgreementService.IsAgreed(currentContact, consent));
        }
コード例 #17
0
        // GET: Consent
        public ActionResult Index()
        {
            var consent = ConsentInfoProvider.GetConsentInfo(TrackingConsentGenerator.CONSENT_NAME);

            if (consent != null)
            {
                var model = new ConsentViewModel
                {
                    ConsentShortText = consent.GetConsentText(Thread.CurrentThread.CurrentUICulture.Name).ShortText
                };

                var contact = ContactManagementContext.CurrentContact;
                if ((contact != null) && mConsentAgreementService.IsAgreed(contact, consent))
                {
                    model.IsConsentAgreed = true;
                }

                return(PartialView("_TrackingConsent", model));
            }

            return(new EmptyResult());
        }
コード例 #18
0
        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"));
        }
コード例 #19
0
 private bool IsDemoEnabled()
 {
     return(ConsentInfoProvider.GetConsentInfo(TrackingConsentGenerator.CONSENT_NAME) != null);
 }