mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
35 lines
974 B
C#
35 lines
974 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Remotely.Shared.Entities;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Remotely.Server.Auth;
|
|
|
|
public class OrganizationAdminRequirementHandler : AuthorizationHandler<OrganizationAdminRequirement>
|
|
{
|
|
private readonly UserManager<RemotelyUser> _userManager;
|
|
|
|
public OrganizationAdminRequirementHandler(UserManager<RemotelyUser> userManager)
|
|
{
|
|
_userManager = userManager;
|
|
}
|
|
|
|
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, OrganizationAdminRequirement requirement)
|
|
{
|
|
if (context.User.Identity?.IsAuthenticated != true)
|
|
{
|
|
context.Fail();
|
|
return;
|
|
}
|
|
|
|
var user = await _userManager.GetUserAsync(context.User);
|
|
if (user?.IsAdministrator != true)
|
|
{
|
|
context.Fail();
|
|
return;
|
|
}
|
|
|
|
context.Succeed(requirement);
|
|
}
|
|
}
|