Skip to content

Commit 74a845f

Browse files
committed
##
1 parent efb5263 commit 74a845f

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8+
<PackageReference Include="AspectCore.Extensions.Reflection" Version="0.7.0" />
89
<PackageReference Include="Microsoft.AspNetCore.App" />
910
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.0" />
1011
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />

APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public ActionResult Add([FromBody]string json)
200200
var dt = new Dictionary<string, object>();
201201
foreach (var f in JObject.Parse(item.Value.ToString()))
202202
{
203-
if (f.Key.ToLower() != "id" && role.Insert.Column.Contains(f.Key, StringComparer.CurrentCultureIgnoreCase))
203+
if (f.Key.ToLower() != "id" && selectTable.IsCol(key, f.Key) && (role.Insert.Column.Contains("*") || role.Insert.Column.Contains(f.Key, StringComparer.CurrentCultureIgnoreCase)))
204204
dt.Add(f.Key, f.Value);
205205
}
206206
int id = db.Db.Insertable(dt).AS(key).ExecuteReturnIdentity();
@@ -252,7 +252,7 @@ public ActionResult Edit([FromBody]string json)
252252
dt.Add("id", value["id"]);
253253
foreach (var f in value)
254254
{
255-
if (f.Key.ToLower() != "id"&& role.Update.Column.Contains(f.Key, StringComparer.CurrentCultureIgnoreCase))
255+
if (f.Key.ToLower() != "id"&& selectTable.IsCol(key,f.Key) && (role.Update.Column.Contains ("*")||role.Update.Column.Contains(f.Key, StringComparer.CurrentCultureIgnoreCase)))
256256
{
257257
dt.Add(f.Key, f.Value);
258258
}
@@ -290,7 +290,7 @@ public ActionResult Remove([FromBody]string json)
290290
string key = item.Key.Trim();
291291
var value = JObject.Parse(item.Value.ToString());
292292
var sb = new System.Text.StringBuilder(100);
293-
sb.Append($"delete [{key}] where");
293+
sb.Append($"delete FROM {key} where");
294294
if (role.Delete==null||role.Delete.Table==null)
295295
{
296296
ht["code"] = "500";

APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public IActionResult Create([FromBody]TokenInput input)
7474
[HttpGet]
7575
public IActionResult GetRole()
7676
{
77-
return Ok(User.Identity.Name);
77+
return Ok(User.FindFirstValue(ClaimTypes.Role));
7878
}
7979
private string CreateAccessToken(IEnumerable<Claim> claims, TimeSpan? expiration = null)
8080
{

APIJSON.NET/APIJSON.NET/SelectTable.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Collections.Generic;
99
using System.Dynamic;
1010
using System.Linq;
11-
using System.Reflection;
11+
using AspectCore.Extensions.Reflection;
1212
using System.Text.RegularExpressions;
1313

1414
public class SelectTable
@@ -50,14 +50,19 @@ public bool IsCol(string table, string col)
5050
/// <returns></returns>
5151
public object ExecFunc(string funcname,object[] param, Type[] types)
5252
{
53-
Type type = typeof(FuncList);
54-
Object obj = Activator.CreateInstance(type);
55-
MethodInfo mt = type.GetMethod(funcname,types);
56-
if (mt==null)
57-
{
58-
throw new Exception($"{funcname}没有获取到相应的函数");
59-
}
60-
return mt.Invoke(obj, param);
53+
var method = typeof(FuncList).GetMethod(funcname);
54+
55+
var reflector = method.GetReflector();
56+
var result = reflector.Invoke(new FuncList(), param);
57+
//Type type = typeof(FuncList);
58+
//Object obj = Activator.CreateInstance(type);
59+
//MethodInfo mt = type.GetMethod(funcname,types);
60+
//if (mt==null)
61+
//{
62+
// throw new Exception($"{funcname}没有获取到相应的函数");
63+
//}
64+
//return mt.Invoke(obj, param);
65+
return result;
6166
}
6267

6368
public (dynamic,int) GetTableData(string subtable, int page, int count, string json, JObject dd)

APIJSON.NET/APIJSON.NET/Startup.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void ConfigureServices(IServiceCollection services)
6060
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
6161
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
6262
{
63+
app.UseAuthentication();
6364
app.UseMvc(routes =>
6465
{
6566
routes.MapRoute(
@@ -74,7 +75,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
7475
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
7576

7677
});
77-
app.UseAuthentication();
78+
7879
app.UseJwtTokenMiddleware();
7980
DbInit.Initialize(app);
8081
}

0 commit comments

Comments
 (0)