Exemple #1
0
    public async Task Invoke(HttpContext context, WaitlistDataContext db)
    {
        _Db = db;

        //If user is not authenticated
        if (!context.User.Identity.IsAuthenticated)
        {
            await _next.Invoke(context);
        }
        else
        {
            var account = _Db.Accounts.Include(c => c.AccountBans).FirstOrDefault(
                c => c.Id == context.User.AccountId()
                );

            if (account == null || !account.IsBanned())
            {
                await _next.Invoke(context);
            }
            else
            {
                //context.Request.Headers["X-Requested-With"] >>> {XMLHttpRequest}
                if (context.Request.Headers["X-Requested-With"].ToString() == "XMLHttpRequest")
                {
                    context.Response.StatusCode = 404;
                    await _next.Invoke(context);
                }


                await context.SignOutAsync();

                context.Response.Redirect("/error/banned");
            }
        }
    }
Exemple #2
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
    public async Task StartAsync(CancellationToken cancellationToken)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
    {
        // Create a new scope to retrieve scoped services
        var scope = _serviceProvider.CreateScope();

        // Get the DbContext instance
        _Db = scope.ServiceProvider.GetRequiredService <WaitlistDataContext>();

        _timer = new Timer(DoWork, null, TimeSpan.Zero,
                           TimeSpan.FromHours(1));
    }
Exemple #3
0
    public async Task Invoke(HttpContext context, WaitlistDataContext db)
    {
        _Db = db;

        //If user is not authenticated
        if (!context.User.Identity.IsAuthenticated)
        {
            await _next.Invoke(context);
        }
        else
        {
            var user     = context.User as ClaimsPrincipal;
            var identity = user.Identity as ClaimsIdentity;

            var claims = user.Claims.Where(c => c.Type == ClaimTypes.Role).ToArray();

            for (int i = 0; i < claims.Length; i++)
            {
                identity.RemoveClaim(claims[i]);
            }

            var roles = _Db.Accounts.Include(a => a.AccountRoles).ThenInclude(ar => ar.Role)
                        .Where(a => a.Id == context.User.AccountId()).SingleOrDefault();

            if (roles != null)
            {
                foreach (var role in roles?.AccountRoles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, role.Role.Name));
                }
            }


            await _next.Invoke(context);
        }
    }
Exemple #4
0
 public WaitlistController(Data.WaitlistDataContext db, ILogger <CommandersController> logger)
 {
     _Db     = db;
     _Logger = logger;
 }