All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 4s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 15m22s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Successful in 1m54s
BCards Deployment Pipeline / Deploy to Test (x86 - Local) (push) Has been skipped
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using BCards.Web.Services;
|
|
|
|
namespace BCards.Web.Middleware
|
|
{
|
|
public class ModerationAuthMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
private readonly IModerationAuthService _moderationAuth;
|
|
|
|
public ModerationAuthMiddleware(RequestDelegate next, IModerationAuthService moderationAuth)
|
|
{
|
|
_next = next;
|
|
_moderationAuth = moderationAuth;
|
|
}
|
|
|
|
public async Task InvokeAsync(HttpContext context)
|
|
{
|
|
var path = context.Request.Path.Value?.ToLowerInvariant();
|
|
|
|
// Verificar se é uma rota de moderação
|
|
if (path != null && path.StartsWith("/moderation"))
|
|
{
|
|
// Verificar se usuário está autenticado
|
|
if (!context.User.Identity?.IsAuthenticated == true)
|
|
{
|
|
context.Response.Redirect("/Auth/Login?returnUrl=" + Uri.EscapeDataString(context.Request.Path));
|
|
return;
|
|
}
|
|
|
|
// Verificar se é moderador
|
|
if (!_moderationAuth.IsUserModerator(context.User))
|
|
{
|
|
context.Response.StatusCode = 403;
|
|
await context.Response.WriteAsync("Acesso negado. Você não tem permissão para acessar esta área.");
|
|
return;
|
|
}
|
|
|
|
// Adicionar flag para usar nas views
|
|
context.Items["IsModerator"] = true;
|
|
}
|
|
|
|
await _next(context);
|
|
}
|
|
}
|
|
}
|