diff --git a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj index f5ecb28..4958ed8 100644 --- a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj +++ b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.1 @@ -15,12 +15,18 @@ - - - - - - + + + + + + + + + + + + diff --git a/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs b/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs index 5f31353..a87f13a 100644 --- a/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs +++ b/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs @@ -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 { diff --git a/APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs b/APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs index df765fc..2979019 100644 --- a/APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs +++ b/APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs @@ -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; @@ -17,6 +18,7 @@ namespace APIJSON.NET.Controllers [Route("api/[controller]/[action]")] [ApiController] [Authorize] + [EnableCors("localhost")] public class TokenController : ControllerBase { private DbContext db; @@ -28,7 +30,7 @@ public TokenController(DbContext _db, IOptions configura } [HttpPost("/token")] [AllowAnonymous] - public IActionResult Create([FromBody]TokenInput input) + public ActionResult Create([FromBody]TokenInput input) { JObject ht = new JObject(); ht.Add("code", "200"); @@ -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)); } diff --git a/APIJSON.NET/APIJSON.NET/Dockerfile b/APIJSON.NET/APIJSON.NET/Dockerfile index e680dec..f2e1229 100644 --- a/APIJSON.NET/APIJSON.NET/Dockerfile +++ b/APIJSON.NET/APIJSON.NET/Dockerfile @@ -1,6 +1,7 @@ -FROM microsoft/aspnetcore:latest +FROM microsoft/dotnet:2.1.2-aspnetcore-runtime WORKDIR /app COPY . . + ENTRYPOINT ["dotnet", "APIJSON.NET.dll"] diff --git a/APIJSON.NET/APIJSON.NET/Program.cs b/APIJSON.NET/APIJSON.NET/Program.cs index 8cd90b3..2fa47dc 100644 --- a/APIJSON.NET/APIJSON.NET/Program.cs +++ b/APIJSON.NET/APIJSON.NET/Program.cs @@ -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 { @@ -17,8 +11,9 @@ public static void Main(string[] args) CreateWebHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IWebHostBuilder CreateWebHostBuilder(string[] args) + { + return WebHost.CreateDefaultBuilder(args).UseStartup(); + } } } diff --git a/APIJSON.NET/APIJSON.NET/SelectTable.cs b/APIJSON.NET/APIJSON.NET/SelectTable.cs index ad42c5f..e438c02 100644 --- a/APIJSON.NET/APIJSON.NET/SelectTable.cs +++ b/APIJSON.NET/APIJSON.NET/SelectTable.cs @@ -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; } @@ -134,6 +126,8 @@ private ISugarQueryable 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); @@ -168,6 +162,10 @@ private ISugarQueryable sugarQueryable(string subtable, string se } List conModels = new List(); + 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(); diff --git a/APIJSON.NET/APIJSON.NET/Startup.cs b/APIJSON.NET/APIJSON.NET/Startup.cs index 53cc82a..84a7dd2 100644 --- a/APIJSON.NET/APIJSON.NET/Startup.cs +++ b/APIJSON.NET/APIJSON.NET/Startup.cs @@ -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"; @@ -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>(Configuration.GetSection("RoleList")); services.Configure>(Configuration.GetSection("tablempper")); services.Configure(tokenAuthConfig => @@ -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 => @@ -55,12 +60,15 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); services.AddTransient(); services.AddTransient(); + } // 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( diff --git a/APIJSON.NET/APIJSON.NET/appsettings.json b/APIJSON.NET/APIJSON.NET/appsettings.json index 3955018..ee1c0d2 100644 --- a/APIJSON.NET/APIJSON.NET/appsettings.json +++ b/APIJSON.NET/APIJSON.NET/appsettings.json @@ -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": { @@ -41,8 +41,8 @@ } ], "tablempper": //ӳ - { - "user": "apijson_user" - } - + { + "user": "apijson_user" + } + }