Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Withdraw()
        {
            _consentFeature?.WithdrawConsent();
            if (_consentFeature?.CanTrack == false)
            {
                var userId      = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var currentUser = await _userManager.FindByIdAsync(userId);

                if (currentUser != null)
                {
                    currentUser.CanTrack = false;
                    await _userManager.UpdateAsync(currentUser);
                }
                _logger.Log(LogLevel.Information, "Tracking consent withdrawn");
                return(Ok());
            }

            _logger.Log(LogLevel.Information, "Failed to revoke tracking consent");
            return(StatusCode(500));
        }