Skip to content

同步代码 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2018
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
20 changes: 13 additions & 7 deletions APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
Expand All @@ -15,12 +15,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspectCore.Extensions.Reflection" Version="0.7.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
<PackageReference Include="MySql.Data" Version="8.0.11" />
<PackageReference Include="sqlSugarCore" Version="4.6.4.9" />
<PackageReference Include="AspectCore.Extensions.Reflection" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
<PackageReference Include="MySql.Data" Version="8.0.12" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.18.3" />
<PackageReference Include="SqlKata" Version="1.1.3" />
<PackageReference Include="SqlKata.Execution" Version="1.1.3" />
<PackageReference Include="sqlSugarCore" Version="4.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="3.0.0" />
Expand Down
2 changes: 2 additions & 0 deletions APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
using System.Linq;
using APIJSON.NET.Services;
using System.Reflection;
using Microsoft.AspNetCore.Cors;

[Route("api/[controller]")]
[ApiController]
[EnableCors("localhost")]
public class JsonController : ControllerBase
{

Expand Down
6 changes: 4 additions & 2 deletions APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
Expand All @@ -17,6 +18,7 @@ namespace APIJSON.NET.Controllers
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
[EnableCors("localhost")]
public class TokenController : ControllerBase
{
private DbContext db;
Expand All @@ -28,7 +30,7 @@ public TokenController(DbContext _db, IOptions<TokenAuthConfiguration> configura
}
[HttpPost("/token")]
[AllowAnonymous]
public IActionResult Create([FromBody]TokenInput input)
public ActionResult Create([FromBody]TokenInput input)
{
JObject ht = new JObject();
ht.Add("code", "200");
Expand Down Expand Up @@ -72,7 +74,7 @@ public IActionResult Create([FromBody]TokenInput input)
return Ok(ht);
}
[HttpGet]
public IActionResult GetRole()
public ActionResult GetRole()
{
return Ok(User.FindFirstValue(ClaimTypes.Role));
}
Expand Down
3 changes: 2 additions & 1 deletion APIJSON.NET/APIJSON.NET/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM microsoft/aspnetcore:latest
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime

WORKDIR /app
COPY . .


ENTRYPOINT ["dotnet", "APIJSON.NET.dll"]
17 changes: 6 additions & 11 deletions APIJSON.NET/APIJSON.NET/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Net;

namespace APIJSON.NET
{
Expand All @@ -17,8 +11,9 @@ public static void Main(string[] args)
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
}
}
}
14 changes: 6 additions & 8 deletions APIJSON.NET/APIJSON.NET/SelectTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ public object ExecFunc(string funcname,object[] param, Type[] types)

var reflector = method.GetReflector();
var result = reflector.Invoke(new FuncList(), param);
//Type type = typeof(FuncList);
//Object obj = Activator.CreateInstance(type);
//MethodInfo mt = type.GetMethod(funcname,types);
//if (mt==null)
//{
// throw new Exception($"{funcname}没有获取到相应的函数");
//}
//return mt.Invoke(obj, param);
return result;
}

Expand Down Expand Up @@ -134,6 +126,8 @@ private ISugarQueryable<ExpandoObject> sugarQueryable(string subtable, string se
throw new Exception($"表名{subtable}不正确!");
}
var tb = db.Db.Queryable(subtable, "tb");


if (values["@column"].IsValue())
{
var str = new System.Text.StringBuilder(100);
Expand Down Expand Up @@ -168,6 +162,10 @@ private ISugarQueryable<ExpandoObject> sugarQueryable(string subtable, string se
}

List<IConditionalModel> conModels = new List<IConditionalModel>();
if (values["identity"].IsValue())
{
conModels.Add(new ConditionalModel() { FieldName = values["identity"].ToString(), ConditionalType = ConditionalType.Equal, FieldValue = _identitySvc.GetUserIdentity() });
}
foreach (var va in values)
{
string vakey = va.Key.Trim();
Expand Down
16 changes: 12 additions & 4 deletions APIJSON.NET/APIJSON.NET/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using SqlKata.Execution;
using Swashbuckle.AspNetCore.Swagger;
using MySql.Data.MySqlClient;
using SqlKata.Compilers;

public class Startup
{
private const string _defaultCorsPolicyName = "localhost";
Expand All @@ -26,8 +30,7 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{



services.Configure<List<Role>>(Configuration.GetSection("RoleList"));
services.Configure<Dictionary<string,string>>(Configuration.GetSection("tablempper"));
services.Configure<TokenAuthConfiguration>(tokenAuthConfig =>
Expand All @@ -40,9 +43,11 @@ public void ConfigureServices(IServiceCollection services)
});
AuthConfigurer.Configure(services, Configuration);

services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName, builder => builder.AllowAnyOrigin()
services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName,
builder =>
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyMethod().AllowCredentials()
));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c =>
Expand All @@ -55,12 +60,15 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IIdentityService, IdentityService>();
services.AddTransient<ITableMapper, TableMapper>();

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{

app.UseAuthentication();

app.UseMvc(routes =>
{
routes.MapRoute(
Expand Down
10 changes: 5 additions & 5 deletions APIJSON.NET/APIJSON.NET/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ConnectionStrings": {
"DbType": 0, //0:MySql,1:SqlServer,2:Sqlite
//"ConnectionString": "Server=liaozengbo\\sql2018; Database=test; User Id=sa;Password=sa123;",
"ConnectionString": "Server=192.168.0.133; Database=test; User Id=root;Password=password;charset=UTF8;"
"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;"
},
"Authentication": {
"JwtBearer": {
Expand Down Expand Up @@ -41,8 +41,8 @@
}
],
"tablempper": //������ӳ��
{
"user": "apijson_user"
}
{
"user": "apijson_user"
}

}