mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
@@ -1,17 +1,15 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace SharpbinV3.Server.Authorization
|
||||
{
|
||||
public sealed class NotBannedHandler(bool requireAuth = false)
|
||||
: AuthorizationHandler<NotBannedRequirement>
|
||||
public sealed class NotBannedHandler(bool requireAuth = false) : AuthorizationHandler<NotBannedRequirement>
|
||||
{
|
||||
private readonly bool _requireAuth = requireAuth;
|
||||
|
||||
protected override Task HandleRequirementAsync(
|
||||
AuthorizationHandlerContext context,
|
||||
NotBannedRequirement requirement
|
||||
)
|
||||
NotBannedRequirement requirement)
|
||||
{
|
||||
var isAuthenticated = context.User.Identity?.IsAuthenticated ?? false;
|
||||
|
||||
@@ -19,8 +17,8 @@ namespace SharpbinV3.Server.Authorization
|
||||
return Task.CompletedTask;
|
||||
|
||||
var isBanned = context.User.Claims.Any(c =>
|
||||
(c.Type == ClaimTypes.Role || c.Type == "role") && c.Value == "403"
|
||||
);
|
||||
(c.Type == ClaimTypes.Role || c.Type == "role") &&
|
||||
c.Value == "403");
|
||||
|
||||
if (!isBanned)
|
||||
context.Succeed(requirement);
|
||||
|
||||
Reference in New Issue
Block a user