Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions APIJSON.NET/APIJSON.NET.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using RestSharp;
using System;
using System.Text.RegularExpressions;

namespace APIJSON.NET.Test
{
Expand Down
3 changes: 2 additions & 1 deletion APIJSON.NET/APIJSON.NET/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class HomeController : Controller
{
public IActionResult Index()
{
return Redirect("index.html");
return File("./index.html", "text/html");
//return Redirect("index.html");
}
}
}
33 changes: 30 additions & 3 deletions APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public ActionResult Test()

public async Task<ActionResult> Query([FromBody] JObject jobject)
{
JObject resultJobj = new SelectTable(_identitySvc, _tableMapper, db.Db).Query(jobject);
var st = new SelectTable(_identitySvc, _tableMapper, db.Db);
JObject resultJobj = st.Query(jobject);
return Ok(resultJobj);
}

Expand All @@ -75,20 +76,46 @@ public async Task<ActionResult> QueryByTable([FromRoute]string table)

JObject jobject = JObject.Parse(json);
ht.Add(table + "[]", jobject);
ht.Add("total@", "");

if (jobject["query"] != null && jobject["query"].ToString() != "0" && jobject["total@"] == null)
{
//自动添加总计数量
ht.Add("total@", "");
}

//每页最大1000条数据
if (jobject["count"] != null && int.Parse(jobject["count"].ToString()) > 1000)
{
throw new Exception("count分页数量最大不能超过1000");
}

bool isDebug = (jobject["@debug"] != null && jobject["@debug"].ToString() != "0");
jobject.Remove("@debug");

bool hasTableKey = false;
List<string> ignoreConditions = new List<string> { "page", "count", "query" };
JObject tableConditions = new JObject();//表的其它查询条件,比如过滤,字段等
foreach (var item in jobject)
{
if (item.Key.Equals(table, StringComparison.CurrentCultureIgnoreCase))
{
hasTableKey = true;
break;
}
if (!ignoreConditions.Contains(item.Key.ToLower()))
{
tableConditions.Add(item.Key, item.Value);
}
}

foreach (var removeKey in tableConditions)
{
jobject.Remove(removeKey.Key);
}

if (!hasTableKey)
{
jobject.Add(table, new JObject());
jobject.Add(table, tableConditions);
}

return await Query(ht);
Expand Down
44 changes: 40 additions & 4 deletions APIJSON.NET/APIJSON.NET/Services/IdentityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,47 @@

namespace APIJSON.NET.Services
{
/// <summary>
///
/// </summary>
public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context;
private List<Role> roles;

/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="_roles"></param>
public IdentityService(IHttpContextAccessor context, IOptions<List<Role>> _roles)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
roles = _roles.Value;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public string GetUserIdentity()
{
return _context.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public string GetUserRoleName()
{
return _context.HttpContext.User.FindFirstValue(ClaimTypes.Role);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public Role GetRole()
{
var role = new Role();
Expand All @@ -43,23 +65,37 @@ public Role GetRole()
}
return role;
}
public (bool, string) GetSelectRole(string table)

/// <summary>
///
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public Tuple<bool, string> GetSelectRole(string table)
{
var role = GetRole();
if (role == null || role.Select == null || role.Select.Table == null)
{
return (false, $"appsettings.json权限配置不正确!");
return Tuple.Create(false, $"appsettings.json权限配置不正确!");
}
string tablerole = role.Select.Table.FirstOrDefault(it => it == "*" || it.Equals(table, StringComparison.CurrentCultureIgnoreCase));

if (string.IsNullOrEmpty(tablerole))
{
return (false, $"表名{table}没权限查询!");
return Tuple.Create(false, $"表名{table}没权限查询!");
}
int index = Array.IndexOf(role.Select.Table, tablerole);
string selectrole = role.Select.Column[index];
return (true, selectrole);
return Tuple.Create(true, selectrole);
}


/// <summary>
///
/// </summary>
/// <param name="col"></param>
/// <param name="selectrole"></param>
/// <returns></returns>
public bool ColIsRole(string col, string[] selectrole)
{
if (selectrole.Contains("*"))
Expand Down
8 changes: 4 additions & 4 deletions APIJSON.NET/APIJSON.NET/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

app.UseAuthentication();

app.UseRouting();
app.UseAuthentication();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseCors(_defaultCorsPolicyName);
app.UseSwagger();
Expand All @@ -84,7 +83,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapDefaultControllerRoute();
//endpoints.MapControllers();
});
app.UseJwtTokenMiddleware();
DbInit.Initialize(app);
Expand Down
6 changes: 3 additions & 3 deletions APIJSON.NET/APIJSON.NET/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
"DbType": 0, //0:MySql,1:SqlServer,2:Sqlite
"ConnectionString": "Server=192.168.2.25;Database=yunwei;Uid=root;Pwd=xmjk;Port=3306;Character Set=utf8;"
"ConnectionString": "Server=192.168.2.25;Database=yunwei1.8;Uid=root;Pwd=xmjk;Port=3306;Character Set=utf8;"
//"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;"
},
"CorsUrls": "http://localhost:5000,http://localhost5001",
Expand All @@ -17,8 +17,8 @@
{
"name": "role1", //Ȩ������ Ψһ
"select": { //��ѯȨ��
"table": [ "moment", "User", "Comment" ], //�ɲ����ı�
"column": [ "*", "*", "*" ], //�ɲ������ֶ�
"table": [ "*" ], //�ɲ����ı�
"column": [ "*" ], //�ɲ������ֶ�
"where": []
},
"update": { //�޸�Ȩ��
Expand Down
2 changes: 1 addition & 1 deletion APIJSON.NET/APIJSON.NET/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<option value="add">add</option>
<option value="edit">edit</option>
<option value="remove">remove</option>
<!--<option value="org">org</option>-->
<option value="org">org</option>

</select>
<button @click="hpost()">发送请求</button>
Expand Down
3 changes: 1 addition & 2 deletions APIJSON.NET/APIJSON.NET/wwwroot/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@
},
methods: {
hpost: function () {

$.ajax({
url: $('#rest-url').val(),
type: "POST", dataType: "json",
contentType: "application/json;charset=utf-8",
data: $('#vInput').val(),
data: $('#vInput').val(),//JSON.stringify($('#vInput').val()),
success: function (data) {

App.jsonhtml = data;
Expand Down
22 changes: 17 additions & 5 deletions APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.1</Version>
<Description>通用查询组件</Description>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>0.0.11</Version>
<Description>
0.0.11 升级sqlSugarCore版本 解决如果查找字段是关键字(例如:key)时出错的问题
0.0.10 处理别名如果为关键字的缺陷
0.0.8 清理SelectTable 支持重载
0.0.7 修复not in的缺陷,增加~ 不等于的支持
0.0.6 增加ToSql接口,处理sql注入的情况
通用查询组件</Description>
<PackageId>ApiJson.Common.Core</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
<Compile Remove="SelectTable - 副本.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4" />
<PackageReference Include="sqlSugarCore" Version="5.0.0.15" />
<PackageReference Include="sqlSugarCore" Version="5.0.5.5" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ApiJson.Common")]
[assembly: AssemblyDescription("增加ToSql接口,处理sql注入的情况")]
[assembly: AssemblyDescription("0.0.19 处理别名如果为关键字的缺陷")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ApiJson.Common")]
Expand All @@ -31,5 +31,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.6.0")]
[assembly: AssemblyFileVersion("0.0.6.0")]
[assembly: AssemblyVersion("0.0.10.0")]
[assembly: AssemblyFileVersion("0.0.10.0")]
Loading