//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)); }
/// <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"); }
/// <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"); }
/// <summary> /// Constructor. /// You can use a dependency injection container to initialize required services and providers. /// </summary> public RegisterWithConsentController(IEventLogService eventLogService, IFormConsentAgreementService formConsentAgreementService, IUserInfoProvider userInfoProvider, IConsentInfoProvider consentInfoProvider) { this.eventLogService = eventLogService; this.formConsentAgreementService = formConsentAgreementService; this.userInfoProvider = userInfoProvider; // Gets the related consent // Fill in the code name of the appropriate consent object in Kentico consent = consentInfoProvider.Get("SampleRegistrationConsent"); }
public async Task <ActionResult <UrlResponse> > CustomerLogin() { BaseAccessToken clientAccessTokenResult = await _clientOperationsBusinessLogic.ClientCredentialsAccessToken(); ConsentInfo consentResult = await _clientOperationsBusinessLogic.CreateAccountAccessConsents(); string customerLoginResult = await _clientOperationsBusinessLogic.CustomerLogin(); var result = new UrlResponse { url = customerLoginResult }; return(result); }
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")); }
/// <summary> /// Constructor. /// You can use a dependency injection container to initialize the consent agreement service. /// </summary> public RegisterWithConsentController(IFormConsentAgreementService formConsentAgreementService, SignInManager <ApplicationUser> signInManager, ApplicationUserManager <ApplicationUser> userManager, IEventLogService eventLogService, IConsentInfoProvider consentInfoProvider) { this.formConsentAgreementService = formConsentAgreementService; this.signInManager = signInManager; this.userManager = userManager; this.eventLogService = eventLogService; // Gets the related consent // Fill in the code name of the appropriate consent object in Xperience consent = consentInfoProvider.Get("SampleRegistrationConsent"); }
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; } } }
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")); }
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); }
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")); }
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 var consentAgreementService = Service.Resolve <IConsentAgreementService>(); // Gets the consent object based on its code name ConsentInfo consent = ConsentInfo.Provider.Get(ConsentCodeName); if (consent == null || currentContact == null) { return(false); } // Checks if the contact has given a consent agreement return(consentAgreementService.IsAgreed(currentContact, consent)); }
public async Task <ConsentInfo> CreateAccountAccessConsents() { ConsentInfo result = null; BankServiceRequest request = new BankServiceRequest() { HeaderParameters = new Dictionary <string, string>() }; var cachedClient = await _cachingService.GetAsync <CacheClientModel>(_rackleClientCacheKey); request.HeaderParameters.Add("access_token", cachedClient.BankCodesClientTokens[Provider.Coutts.Value].AccessToken); BankServiceResponse response = await _bankService.CreateAccountAccessConsents(request); if (response.StatusCode == System.Net.HttpStatusCode.Created) { JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); result = new ConsentInfo() { ConsentId = responseJson.RootElement.GetProperty("Data").GetProperty("ConsentId").GetString(), CreationDateTime = responseJson.RootElement.GetProperty("Data").GetProperty("CreationDateTime").GetString(), Status = responseJson.RootElement.GetProperty("Data").GetProperty("Status").GetString(), StatusUpdateDateTime = responseJson.RootElement.GetProperty("Data").GetProperty("StatusUpdateDateTime").GetString(), }; } var cachedUser = await _cachingService.GetAsync <CacheUserModel>("UserId-" + _authContext.UserId); if (!cachedUser.BankCodesConsentInfos.ContainsKey(Provider.Coutts.Value)) { cachedUser.BankCodesConsentInfos.Add(Provider.Coutts.Value, result); } else { cachedUser.BankCodesConsentInfos[Provider.Coutts.Value] = result; } await _cachingService.SetAsync <CacheUserModel>("UserId-" + _authContext.UserId, cachedUser); return(result); }
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)); }
public static async void setConsented(Sitecore.Analytics.Tracking.Contact contact, SiteContext context, Boolean consent) { if (contact != null && context != null) { Item rootItem = Sitecore.Context.Database.GetItem(context.RootPath); ReferenceField xconsentPolicyField = rootItem.Fields["XConsent Policy"]; Item xconsentPolicy = xconsentPolicyField.TargetItem; if (rootItem != null && xconsentPolicy != null) { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var contactReference = new ContactReference(contact.ContactId); Task <Contact> contactTask = client.GetContactAsync(contactReference, new ContactExpandOptions() { }); Contact XContact = await contactTask; var facet = XContact.GetFacet <ConsentInfo>(ConsentInfo.DefaultFacetKey); if (facet != null) { if (facet.Consents != null) { ConsentObject obj = facet.Consents.FirstOrDefault <ConsentObject>(x => x.rootId.Equals(rootItem.ID) && x.language.Equals(context.Language) && x.policyId.Equals(xconsentPolicy.ID) && x.policyVersion.Equals(xconsentPolicy.Version.Number)); if (obj != null) { obj.consent = consent; } else { facet.Consents.Add(new ConsentObject(rootItem.ID, xconsentPolicy.ID, xconsentPolicy.Version.Number, context.Language, consent)); } // Set the updated facet client.SetFacet(XContact, ConsentInfo.DefaultFacetKey, facet); } } else { facet = new ConsentInfo(); facet.Consents.Add(new ConsentObject(rootItem.ID, xconsentPolicy.ID, xconsentPolicy.Version.Number, context.Language, consent)); } await client.SubmitAsync(); } catch (XdbExecutionException ex) { // Handle exception } } } } }
private static string GetParentConsentUrl(ConsentInfo consent) { var uiElementUrl = UIContextHelper.GetElementUrl("CMS.DataProtection", "Consents.ConsentArchive"); return($"{uiElementUrl}&parentobjectid={consent.ConsentID}&displaytitle={false}"); }