网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
using System.Linq;
using System.Threading.Tasks;
using Dpz.Core.EnumLibrary;
using Hangfire.Dashboard;
using Microsoft.AspNetCore.Authentication;

namespace Dpz.Core.Web.Library;

public class HangfireFilter: IDashboardAuthorizationFilter
{
    public bool Authorize(DashboardContext context)
    {
        var authenticateResult = Task.Run(() => context.GetHttpContext().AuthenticateAsync(Program.AuthorizeCookieName)).Result;
        if (authenticateResult is { Succeeded: true, Principal.Identity.IsAuthenticated: true })
        {
            var userInfo = authenticateResult.Principal.GetIdentity();
            var permissible = (userInfo.Permissions?.ToString() ?? "").Split(",").Select(x => x.Trim()).ToList();
            return permissible.Contains(Permissions.System.ToString());
        }
        return false;
    }
}
loading