为什么都没了
This commit is contained in:
24
framework/Api/Ewide.Web.Core/Ewide.Web.Core.csproj
Normal file
24
framework/Api/Ewide.Web.Core/Ewide.Web.Core.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<NoWarn>1701;1702;1591</NoWarn>
|
||||
<DocumentationFile>Ewide.Web.Core.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Ewide.Web.Core.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0-preview.1.21102.12" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Ewide.NbzsZheliban\Ewide.NbzsZheliban.csproj" />
|
||||
<ProjectReference Include="..\Ewide.Database.Migrations\Ewide.Database.Migrations.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
36
framework/Api/Ewide.Web.Core/Ewide.Web.Core.xml
Normal file
36
framework/Api/Ewide.Web.Core/Ewide.Web.Core.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Ewide.Web.Core</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:Ewide.Web.Core.JwtHandler.HandleAsync(Microsoft.AspNetCore.Authorization.AuthorizationHandlerContext)">
|
||||
<summary>
|
||||
重写 Handler 添加自动刷新
|
||||
</summary>
|
||||
<param name="context"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Ewide.Web.Core.JwtHandler.PipelineAsync(Microsoft.AspNetCore.Authorization.AuthorizationHandlerContext,Microsoft.AspNetCore.Http.DefaultHttpContext)">
|
||||
<summary>
|
||||
授权判断逻辑,授权通过返回 true,否则返回 false
|
||||
</summary>
|
||||
<param name="context"></param>
|
||||
<param name="httpContext"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Ewide.Web.Core.JwtHandler.CheckAuthorzieAsync(Microsoft.AspNetCore.Http.DefaultHttpContext)">
|
||||
<summary>
|
||||
检查权限
|
||||
</summary>
|
||||
<param name="httpContext"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Ewide.Web.Core.Service.DBqueryService.GetDataBase">
|
||||
<summary>
|
||||
读取数据库的所有表 并拿到数据
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
78
framework/Api/Ewide.Web.Core/Handlers/JwtHandler.cs
Normal file
78
framework/Api/Ewide.Web.Core/Handlers/JwtHandler.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Service;
|
||||
using Furion;
|
||||
using Furion.Authorization;
|
||||
using Furion.DataEncryption;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Ewide.Web.Core
|
||||
{
|
||||
public class JwtHandler : AppAuthorizeHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 重写 Handler 添加自动刷新
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task HandleAsync(AuthorizationHandlerContext context)
|
||||
{
|
||||
// 自动刷新Token
|
||||
if (JWTEncryption.AutoRefreshToken(context, context.GetCurrentHttpContext()))
|
||||
{
|
||||
await AuthorizeHandleAsync(context);
|
||||
}
|
||||
else context.Fail(); // 授权失败
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 授权判断逻辑,授权通过返回 true,否则返回 false
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
|
||||
{
|
||||
// 此处已经自动验证 Jwt Token的有效性了,无需手动验证
|
||||
return await CheckAuthorzieAsync(httpContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查权限
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
private static async Task<bool> CheckAuthorzieAsync(DefaultHttpContext httpContext)
|
||||
{
|
||||
// 管理员跳过判断
|
||||
var userManager = App.GetService<IUserManager>();
|
||||
if (userManager.SuperAdmin) return true;
|
||||
|
||||
// 路由名称
|
||||
var routeName = httpContext.Request.Path.Value.Substring(1).Replace("/", ":");
|
||||
|
||||
// 默认路由(获取登录用户信息)
|
||||
var defalutRoute = App.Configuration.GetSection("CoreSettings:DefalutRoute").Get<List<string>>();
|
||||
//var defalutRoute = new List<string>()
|
||||
//{
|
||||
// "getLoginUser",
|
||||
// "logout",
|
||||
// "sysFileInfo:upload",
|
||||
// "sysFileInfo:download",
|
||||
// "sysFileInfo:preview",
|
||||
// "sysUser:updateInfo"
|
||||
//};
|
||||
|
||||
if (defalutRoute.Contains(routeName)) return true;
|
||||
|
||||
// 获取用户权限集合(按钮或API接口)
|
||||
var permissionList = await userManager.GetLoginPermissionList();
|
||||
|
||||
// 检查授权
|
||||
return permissionList.Contains(routeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
framework/Api/Ewide.Web.Core/Service/DBqueryService.cs
Normal file
67
framework/Api/Ewide.Web.Core/Service/DBqueryService.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Ewide.Core.Util;
|
||||
using Ewide.EntityFramework.Core;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Web.Core.Service
|
||||
{
|
||||
[ApiDescriptionSettings(Name = "DBHandler", Order = 3)]
|
||||
public class DBqueryService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly DefaultDbContext _db;
|
||||
|
||||
public DBqueryService(DefaultDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
[HttpGet("/DBreader/detail")]
|
||||
[AllowAnonymous]
|
||||
public async Task XMLDoneAsync()
|
||||
{
|
||||
#if DEBUG
|
||||
XmlSerializerUtil xmlHandler = new XmlSerializerUtil();
|
||||
//xmlHandler.WriteDataSeed();
|
||||
//拿到数据保存到 XML文件
|
||||
Dictionary<string, object> dicDataBase = await GetDataBase();
|
||||
foreach (KeyValuePair<string, object> item in dicDataBase)
|
||||
{
|
||||
xmlHandler.WriteXML(item.Value.GetType(), item.Value, item.Key);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取数据库的所有表 并拿到数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<Dictionary<string, object>> GetDataBase()
|
||||
{
|
||||
Dictionary<string, object> dicDataBase = new Dictionary<string, object>();
|
||||
var defaultConnection = App.Configuration["ConnectionStrings:DefaultConnection"];
|
||||
//获取 所有继承 IEntity 接口的表
|
||||
IEnumerable<IEntityType> entityTypedb = _db.Model.GetEntityTypes().Where(x => typeof(IEntity).IsAssignableFrom(x.ClrType)).ToList();
|
||||
|
||||
foreach (IEntityType item in entityTypedb)
|
||||
{
|
||||
MethodInfo mi = _db.GetType().GetMethods().FirstOrDefault(s => s.Name == "Set");
|
||||
MethodInfo miConstructed = mi.MakeGenericMethod(item.ClrType);
|
||||
object objList = miConstructed.Invoke(_db, null);
|
||||
var objsource = item.ClrType.MakeList(objList);
|
||||
dicDataBase.Add(item.ClrType.Name, objsource);
|
||||
}
|
||||
await _db.Database.CloseConnectionAsync();
|
||||
return dicDataBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
83
framework/Api/Ewide.Web.Core/Startup.cs
Normal file
83
framework/Api/Ewide.Web.Core/Startup.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Ewide.Core;
|
||||
using Furion;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Ewide.Web.Core
|
||||
{
|
||||
public class Startup : AppStartup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);
|
||||
|
||||
services.AddCorsAccessor();
|
||||
|
||||
services.AddRemoteRequest();
|
||||
|
||||
services.AddConfigurableOptions<CacheOptions>();
|
||||
|
||||
services.AddControllersWithViews()
|
||||
.AddMvcFilter<RequestActionFilter>()
|
||||
.AddInjectWithUnifyResult<RestfulResultProvider>()
|
||||
// 在管道中增加NewtonsoftJson,防止参数类型严格验证
|
||||
.AddNewtonsoftJson(options => {
|
||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
})
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
//options.JsonSerializerOptions.DefaultBufferSize = 10_0000;//返回较大数据数据序列化时会截断,原因:默认缓冲区大小(以字节为单位)为16384。
|
||||
options.JsonSerializerOptions.Converters.AddDateFormatString("yyyy-MM-dd HH:mm:ss");
|
||||
//options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; // 忽略循环引用 仅.NET 6支持
|
||||
});
|
||||
|
||||
services.AddViewEngine();
|
||||
|
||||
// 设置雪花id的workerId,确保每个实例workerId都应不同
|
||||
//var workerId = ushort.Parse(App.Configuration["SnowId:WorkerId"] ?? "1");
|
||||
//IDGenerator.SetIdGenerator(new IDGeneratorOptions { WorkerId = workerId });
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
// 添加状态码拦截中间件
|
||||
app.UseUnifyResultStatusCodes();
|
||||
|
||||
app.UseHttpsRedirection(); // 强制https
|
||||
app.UseStaticFiles();
|
||||
|
||||
// Serilog请求日志中间件---必须在 UseStaticFiles 和 UseRouting 之间
|
||||
app.UseSerilogRequestLogging();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseCorsAccessor();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseInject(string.Empty);
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user