2020-03-30 10:12:52 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Encodings.Web;
|
|
|
|
|
using System.Text.Unicode;
|
2020-04-08 14:38:39 +08:00
|
|
|
|
using Falcon.Extend;
|
2020-03-30 10:12:52 +08:00
|
|
|
|
using FAuth.DataBase;
|
2020-04-13 08:35:54 +08:00
|
|
|
|
using FAuth.Extensions;
|
2020-04-20 11:41:09 +08:00
|
|
|
|
using FAuth.Extensions.Account;
|
2020-04-08 16:28:42 +08:00
|
|
|
|
using FAuth.Extensions.Decryptor;
|
2020-03-30 10:12:52 +08:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-04-10 18:15:11 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2020-03-30 10:12:52 +08:00
|
|
|
|
using Microsoft.Extensions.Caching.Redis;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.OpenApi.Models;
|
2020-04-16 08:48:17 +08:00
|
|
|
|
using Microsoft.OpenApi.Writers;
|
2020-03-30 10:12:52 +08:00
|
|
|
|
|
|
|
|
|
namespace FAuth
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
public Startup(IConfiguration configuration) {
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ע<>ᵽ<EFBFBD><E1B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|
|
|
|
public void ConfigureServices(IServiceCollection services) {
|
|
|
|
|
//ע<><D7A2>Json<6F><6E><EFBFBD>л<EFBFBD>
|
2020-04-08 14:38:39 +08:00
|
|
|
|
services.AddMsJsonProvider();
|
2020-03-30 10:12:52 +08:00
|
|
|
|
//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
2020-04-10 18:15:11 +08:00
|
|
|
|
services.AddDbContext<FAuthDb>(option => {
|
2020-04-22 20:59:52 +08:00
|
|
|
|
//option.UseSqlServer(this.Configuration.GetValue<string>("Database:FAuthDbSqlServer"));
|
2020-04-23 10:05:05 +08:00
|
|
|
|
option.UseMySQL(this.Configuration.GetValue<string>("Database:FAuthDbMySql"));
|
|
|
|
|
//var dbType = this.Configuration.GetValue<string>("Database:UseDb").ToLower();
|
|
|
|
|
//switch(dbType) {
|
|
|
|
|
// case "mysql":
|
|
|
|
|
// option.UseMySQL(this.Configuration.GetValue<string>("Database:FAuthDbMySql"));
|
|
|
|
|
// break;
|
|
|
|
|
// case "sqlserver":
|
|
|
|
|
// option.UseSqlServer(this.Configuration.GetValue<string>("Database:FAuthDbSqlServer"));
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// throw new Exception("Database:UseDb<44><62><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ϊmysql<71><6C>sqlserver");
|
|
|
|
|
//}
|
2020-04-10 18:15:11 +08:00
|
|
|
|
});
|
2020-04-20 11:41:09 +08:00
|
|
|
|
services.AddAccountHelper();
|
2020-03-30 10:12:52 +08:00
|
|
|
|
//ע<><D7A2>Redis
|
|
|
|
|
var rop = this.Configuration.GetSection("Redis").Get<RedisCacheOptions>();
|
2020-04-08 14:38:39 +08:00
|
|
|
|
services.AddRedis(rop);
|
2020-03-30 10:12:52 +08:00
|
|
|
|
//ע<><D7A2>MVC
|
|
|
|
|
services.AddControllersWithViews()
|
|
|
|
|
.AddJsonOptions(option => {
|
|
|
|
|
option.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
|
|
|
|
|
option.JsonSerializerOptions.PropertyNamingPolicy = null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//ע<><D7A2>Swagger
|
|
|
|
|
services.AddSwaggerGen(c => {
|
|
|
|
|
c.SwaggerDoc("V1",new OpenApiInfo {
|
|
|
|
|
Title = "<22>ӿ<EFBFBD><D3BF>ĵ<EFBFBD>",
|
|
|
|
|
Version = "1.0",
|
2020-03-30 16:10:51 +08:00
|
|
|
|
Description = "api",
|
|
|
|
|
Contact = new OpenApiContact {
|
|
|
|
|
Name = "Falcon",
|
|
|
|
|
Url = new Uri("http://39.105.71.191/Falcon/FAuth"),
|
|
|
|
|
},
|
2020-03-30 10:12:52 +08:00
|
|
|
|
});
|
|
|
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory,typeof(Program).Assembly.GetName().Name + ".xml");
|
|
|
|
|
c.IncludeXmlComments(xmlPath,true);
|
2020-04-08 14:38:39 +08:00
|
|
|
|
c.AddXmlEnumEnable(xmlPath);
|
2020-03-30 10:12:52 +08:00
|
|
|
|
});
|
2020-04-08 16:28:42 +08:00
|
|
|
|
//ע<><D7A2><EFBFBD>û<EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
services.AddAESCrypto();
|
|
|
|
|
var UTDO = Configuration.GetSection("UserTicketDecryptorOption");
|
|
|
|
|
services.AddUserTicketDryptor(UTDO);
|
2020-04-10 18:15:11 +08:00
|
|
|
|
//ע<><D7A2>api<70><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
services.AddScoped<ApiExceptionFilterAttribute>();
|
2020-03-30 10:12:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app,IWebHostEnvironment env) {
|
|
|
|
|
if(env.IsDevelopment()) {
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
} else {
|
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
}
|
2020-04-16 08:48:17 +08:00
|
|
|
|
|
2020-04-22 17:52:22 +08:00
|
|
|
|
using(var socpe = app.ApplicationServices.CreateScope()) {
|
2020-04-16 08:48:17 +08:00
|
|
|
|
var db = socpe.ServiceProvider.GetService<FAuthDb>();
|
|
|
|
|
db.InitSync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 10:12:52 +08:00
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI(c => {
|
|
|
|
|
c.SwaggerEndpoint("/swagger/V1/swagger.json","<22>ӿ<EFBFBD><D3BF>ĵ<EFBFBD>");
|
2020-04-10 18:15:11 +08:00
|
|
|
|
c.RoutePrefix = "";
|
2020-03-30 10:12:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints => {
|
|
|
|
|
endpoints.MapControllerRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|