Exemple #1
0
 public async Task Invoke(HttpContext context)
 {
     if (context.Request.Path == "/consent")
     {
         ITrackingConsentFeature consentFeature = context.Features.Get <ITrackingConsentFeature>();
         if (!consentFeature.HasConsent)
         {
             consentFeature.GrantConsent();
         }
         else
         {
             consentFeature.WithdrawConsent();
         }
         await context.Response.WriteAsync(consentFeature.HasConsent? "Consent granted \n" : "Consent withdrawn \n");
     }
     await next(context);
 }
        public async Task Grant()
        {
            _consentFeature?.GrantConsent();
            if (_consentFeature?.CanTrack == true)
            {
                var userId      = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var currentUser = await _userManager.FindByIdAsync(userId);

                if (currentUser != null)
                {
                    currentUser.CanTrack = true;
                    await _userManager.UpdateAsync(currentUser);
                }
                _logger.Log(LogLevel.Information, "Tracking consent granted");
            }
            else
            {
                _logger.Log(LogLevel.Information, "Failed to apply tracking consent");
            }
        }