You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Infrastructure.Web
|
|
{
|
|
public class DeviceAttribute : ActionFilterAttribute
|
|
{
|
|
public static string DeviceId { get; private set; }
|
|
|
|
static DeviceAttribute()
|
|
{
|
|
DeviceId = Helper.Instance.GetCPUNumber();
|
|
}
|
|
|
|
public override void OnResultExecuting(ResultExecutingContext context)
|
|
{
|
|
var config = context.HttpContext.RequestServices.GetService<IConfiguration>();
|
|
if (config["id"] != DeviceId.Md5().Base64UrlEncode().Md5())
|
|
{
|
|
if (!context.HttpContext.Request.Path.Value.StartsWith("/App/"))
|
|
{
|
|
context.Result = new RedirectResult("/Admin/Configuration");
|
|
}
|
|
else
|
|
{
|
|
context.Result = new JsonResult($"设备{DeviceId}的授权码\"{config["id"]}\"异常");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |