protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RestrictAccessToBlockedUsersRequirement requirement)
        {
            var currentUserLogin = context.User.Identity?.Name;

            if (currentUserLogin == null)
            {
                context.Fail();
                return(Task.CompletedTask);
            }

            var blockedUserLogins = citizenUserRepository.GetBlockedUsers().Select(u => u.Login).ToList();

            if (!blockedUserLogins.Contains(currentUserLogin))
            {
                context.Succeed(requirement);
            }
            else
            {
                context.Fail();
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
 public List <CitizenUser> GetBlockedUsers()
 {
     return(citizenUserRepository.GetBlockedUsers().ToList());
 }