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-05-12 11:24:56 +08:00
|
|
|
|
using FAuth.Models;
|
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-24 13:39:31 +08:00
|
|
|
|
services.AddScoped<DbContext,FAuthDb>();
|
2020-04-10 18:15:11 +08:00
|
|
|
|
services.AddDbContext<FAuthDb>(option => {
|
2020-04-24 13:39:31 +08:00
|
|
|
|
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 => {
|
2020-04-26 14:49:31 +08:00
|
|
|
|
var option = this.Configuration.GetSection("SwaggerDoc");
|
2020-03-30 10:12:52 +08:00
|
|
|
|
c.SwaggerDoc("V1",new OpenApiInfo {
|
2020-04-26 14:49:31 +08:00
|
|
|
|
Title = option.GetValue<string>("Title"),
|
|
|
|
|
Version = option.GetValue<string>("Version"),
|
|
|
|
|
Description = option.GetValue<string>("Description"),
|
2020-03-30 16:10:51 +08:00
|
|
|
|
Contact = new OpenApiContact {
|
2020-04-26 14:49:31 +08:00
|
|
|
|
Name = option.GetValue<string>("Contact:Name"),
|
|
|
|
|
Url = new Uri(option.GetValue<string>("Contact:Url")),
|
2020-03-30 16:10:51 +08:00
|
|
|
|
},
|
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-05-12 11:24:56 +08:00
|
|
|
|
//ע<><D7A2>Cookie<69><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
services.Configure<CookieKeyDefine>(this.Configuration.GetSection("CookieKeyDefine"));
|
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.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI(c => {
|
|
|
|
|
c.SwaggerEndpoint("/swagger/V1/swagger.json","<22>ӿ<EFBFBD><D3BF>ĵ<EFBFBD>");
|
2020-05-09 11:44:07 +08:00
|
|
|
|
c.RoutePrefix = "api";
|
2020-03-30 10:12:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
2020-05-09 11:44:07 +08:00
|
|
|
|
app.UseRouting();
|
2020-03-30 10:12:52 +08:00
|
|
|
|
app.UseEndpoints(endpoints => {
|
|
|
|
|
endpoints.MapControllerRoute(
|
|
|
|
|
name: "default",
|
2020-05-09 11:44:07 +08:00
|
|
|
|
pattern: "{controller=Home}/{action=Index}");
|
2020-03-30 10:12:52 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|