mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: totp 2fa; httpcontext extension for jwtuser; asp.net data protection; prevent banned users from certain actions; account deletion requires 2fa if enabled; making users admins requires 2fa if enabled; httpcontext extension to get ip; enhance user store
refactor: organize dtos by domain; verification providers use verification context; move ip parsing into http context extensions chore: clean code
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace SharpbinV3.Server.Authorization
|
||||
{
|
||||
public sealed class NotBannedHandler(bool requireAuth = false) : AuthorizationHandler<NotBannedRequirement>
|
||||
{
|
||||
private readonly bool _requireAuth = requireAuth;
|
||||
|
||||
protected override Task HandleRequirementAsync(
|
||||
AuthorizationHandlerContext context,
|
||||
NotBannedRequirement requirement)
|
||||
{
|
||||
var isAuthenticated = context.User.Identity?.IsAuthenticated ?? false;
|
||||
|
||||
if (_requireAuth && !isAuthenticated)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var isBanned = context.User.Claims.Any(c =>
|
||||
(c.Type == ClaimTypes.Role || c.Type == "role") &&
|
||||
c.Value == "403");
|
||||
|
||||
if (!isBanned)
|
||||
context.Succeed(requirement);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace SharpbinV3.Server.Authorization
|
||||
{
|
||||
public class NotBannedRequirement : IAuthorizationRequirement
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user