优化代码
This commit is contained in:
parent
6e8e649e88
commit
acc10fde4a
@ -37,12 +37,12 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
ConfigId = "0",
|
ConfigId = "0",
|
||||||
ConnectionString = connStr,
|
ConnectionString = connStr,
|
||||||
DbType = (IocDbType)dbType,
|
DbType = (IocDbType)dbType,
|
||||||
IsAutoCloseConnection = true//自动释放
|
IsAutoCloseConnection = true
|
||||||
}, new IocConfig() {
|
}, new IocConfig() {
|
||||||
ConfigId = "1",
|
ConfigId = "1",
|
||||||
ConnectionString = connStrBus,
|
ConnectionString = connStrBus,
|
||||||
DbType = (IocDbType)dbType_bus,
|
DbType = (IocDbType)dbType_bus,
|
||||||
IsAutoCloseConnection = true//自动释放
|
IsAutoCloseConnection = true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//每次Sql执行前事件
|
//每次Sql执行前事件
|
||||||
|
|||||||
@ -34,21 +34,11 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
if (types.GetProperty("Create_by") != null && context != null)
|
if (types.GetProperty("Create_by") != null && context != null)
|
||||||
{
|
{
|
||||||
types.GetProperty("Create_by").SetValue(source, context.GetName(), null);
|
types.GetProperty("Create_by").SetValue(source, context.GetName(), null);
|
||||||
|
|
||||||
// types.GetProperty("CreateName").SetValue(source, userSession.UserName, null);
|
|
||||||
}
|
}
|
||||||
if (types.GetProperty("UserId") != null && context != null)
|
if (types.GetProperty("UserId") != null && context != null)
|
||||||
{
|
{
|
||||||
types.GetProperty("UserId").SetValue(source, context.GetUId(), null);
|
types.GetProperty("UserId").SetValue(source, context.GetUId(), null);
|
||||||
}
|
}
|
||||||
//if (types.GetProperty("UpdateID") != null)
|
|
||||||
//{
|
|
||||||
// types.GetProperty("UpdateID").SetValue(source, userSession.UserID, null);
|
|
||||||
|
|
||||||
// types.GetProperty("UpdateName").SetValue(source, userSession.UserName, null);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,8 +34,6 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
{
|
{
|
||||||
var _tasksQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
var _tasksQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
||||||
|
|
||||||
//此写法不通过有待研究
|
|
||||||
//var _tasksQzService2 = (ISysTasksQzService)services.GetRequiredService(typeof(SysTasksQzService));
|
|
||||||
ITaskSchedulerServer _schedulerServer = App.GetRequiredService<ITaskSchedulerServer>();
|
ITaskSchedulerServer _schedulerServer = App.GetRequiredService<ITaskSchedulerServer>();
|
||||||
|
|
||||||
var tasks = _tasksQzService.GetList(m => m.IsStart);
|
var tasks = _tasksQzService.GetList(m => m.IsStart);
|
||||||
|
|||||||
@ -122,8 +122,8 @@ namespace ZR.Admin.WebApi.Filters
|
|||||||
sysOperLog.jsonResult = logAttribute.IsSaveResponseData ? sysOperLog.jsonResult : "";
|
sysOperLog.jsonResult = logAttribute.IsSaveResponseData ? sysOperLog.jsonResult : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
LogEventInfo ei = new(LogLevel.Info, "GlobalExceptionMiddleware", "");
|
LogEventInfo ei = new(LogLevel.Info, "GlobalActionMonitor", "");
|
||||||
ei.Properties["status"] = 0;
|
|
||||||
ei.Properties["jsonResult"] = !HttpMethods.IsGet(method) ? jsonResult : "";
|
ei.Properties["jsonResult"] = !HttpMethods.IsGet(method) ? jsonResult : "";
|
||||||
ei.Properties["requestParam"] = sysOperLog.operParam;
|
ei.Properties["requestParam"] = sysOperLog.operParam;
|
||||||
ei.Properties["user"] = userName;
|
ei.Properties["user"] = userName;
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Model;
|
using Infrastructure.Model;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
@ -22,9 +20,6 @@ namespace ZR.Admin.WebApi.Filters
|
|||||||
public class VerifyAttribute : Attribute, IAuthorizationFilter
|
public class VerifyAttribute : Attribute, IAuthorizationFilter
|
||||||
{
|
{
|
||||||
static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
//IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
|
||||||
|
|
||||||
//public VerifyAttribute() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 只判断token是否正确,不判断权限
|
/// 只判断token是否正确,不判断权限
|
||||||
@ -45,19 +40,14 @@ namespace ZR.Admin.WebApi.Filters
|
|||||||
string ip = HttpContextExtension.GetClientUserIp(context.HttpContext);
|
string ip = HttpContextExtension.GetClientUserIp(context.HttpContext);
|
||||||
string url = context.HttpContext.Request.Path;
|
string url = context.HttpContext.Request.Path;
|
||||||
var isAuthed = context.HttpContext.User.Identity.IsAuthenticated;
|
var isAuthed = context.HttpContext.User.Identity.IsAuthenticated;
|
||||||
var userName = context.HttpContext.User.Identity.Name;
|
|
||||||
|
|
||||||
//使用jwt token校验2020-11-21
|
//使用jwt token校验2020-11-21
|
||||||
LoginUser info = JwtUtil.GetLoginUser(context.HttpContext);
|
LoginUser info = JwtUtil.GetLoginUser(context.HttpContext);
|
||||||
|
|
||||||
if (info != null && info.UserId > 0)
|
if (info == null || !isAuthed)
|
||||||
{
|
{
|
||||||
//logger.Info($"[{info.UserId}-{userName}-{ip}]用户登录校验成功");
|
string msg = $"请求访问[{url}]失败,无法访问系统资源";
|
||||||
}
|
logger.Info($"{msg}");
|
||||||
else
|
|
||||||
{
|
|
||||||
string msg = $"请求访问:{url}授权认证失败,无法访问系统资源";
|
|
||||||
logger.Info($"用户{userName}{msg}");
|
|
||||||
|
|
||||||
context.Result = new JsonResult(new ApiResult((int)ResultCode.DENY, msg));
|
context.Result = new JsonResult(new ApiResult((int)ResultCode.DENY, msg));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user