From ea544255e0854ae1788fcdbe8ce080f1e6c96eb3 Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Thu, 13 Jul 2023 08:28:34 +0800 Subject: [PATCH 1/8] Add api project --- PearAdmin.AbpTemplate.sln | 23 +- .../Controllers/AccountController.cs | 29 +++ .../PearAdmin.AbpTemplate.Admin.csproj | 2 +- .../AbpTemplateApiModule.cs | 45 ++++ .../Controllers/AntiForgeryController.cs | 28 +++ .../Controllers/HomeController.cs | 50 ++++ .../AbpBootstrapperOptionsExtension.cs | 17 ++ .../Extensions/AuthConfigurerExtension.cs | 77 +++++++ .../Extensions/HostingEnvironmentExtension.cs | 14 ++ .../PearAdmin.AbpTemplate.Api.csproj | 58 +++++ src/PearAdmin.AbpTemplate.Api/Program.cs | 31 +++ .../Properties/launchSettings.json | 28 +++ src/PearAdmin.AbpTemplate.Api/Startup.cs | 135 +++++++++++ .../appsettings.Staging.json | 9 + .../appsettings.json | 28 +++ .../wwwroot/swagger/ui/abp.js | 117 ++++++++++ .../wwwroot/swagger/ui/abp.swagger.js | 214 ++++++++++++++++++ .../wwwroot/swagger/ui/index.html | 146 ++++++++++++ 18 files changed, 1045 insertions(+), 6 deletions(-) create mode 100644 src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/Extensions/AbpBootstrapperOptionsExtension.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj create mode 100644 src/PearAdmin.AbpTemplate.Api/Program.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json create mode 100644 src/PearAdmin.AbpTemplate.Api/Startup.cs create mode 100644 src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json create mode 100644 src/PearAdmin.AbpTemplate.Api/appsettings.json create mode 100644 src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js create mode 100644 src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js create mode 100644 src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html diff --git a/PearAdmin.AbpTemplate.sln b/PearAdmin.AbpTemplate.sln index c84406f..e845ae2 100644 --- a/PearAdmin.AbpTemplate.sln +++ b/PearAdmin.AbpTemplate.sln @@ -39,6 +39,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PearAdmin.AbpTemplate.MiniP EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PearAdmin.AbpTemplate.ExternalAuth", "module\PearAdmin.AbpTemplate.ExternalAuth\PearAdmin.AbpTemplate.ExternalAuth.csproj", "{B55DAA71-4958-485D-8888-E185C2104931}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "app", "app", "{5470CA36-48C3-4283-B1DB-8D168E57F2A7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "service", "service", "{7C235DEB-7400-470D-80AC-003A662F31F3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PearAdmin.AbpTemplate.Api", "src\PearAdmin.AbpTemplate.Api\PearAdmin.AbpTemplate.Api.csproj", "{AF0BE94D-8F47-4FA1-9101-E71699C39F00}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,25 +107,32 @@ Global {B55DAA71-4958-485D-8888-E185C2104931}.Debug|Any CPU.Build.0 = Debug|Any CPU {B55DAA71-4958-485D-8888-E185C2104931}.Release|Any CPU.ActiveCfg = Release|Any CPU {B55DAA71-4958-485D-8888-E185C2104931}.Release|Any CPU.Build.0 = Release|Any CPU + {AF0BE94D-8F47-4FA1-9101-E71699C39F00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF0BE94D-8F47-4FA1-9101-E71699C39F00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF0BE94D-8F47-4FA1-9101-E71699C39F00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF0BE94D-8F47-4FA1-9101-E71699C39F00}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {0FA75A5B-AB83-4FD0-B545-279774C01E87} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} - {3870C648-4AEA-4B85-BA3F-F2F63B96136A} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} + {0FA75A5B-AB83-4FD0-B545-279774C01E87} = {7C235DEB-7400-470D-80AC-003A662F31F3} + {3870C648-4AEA-4B85-BA3F-F2F63B96136A} = {7C235DEB-7400-470D-80AC-003A662F31F3} {0D4C5D00-C144-4213-A007-4B8944113AB1} = {F10AA149-2626-486E-85BB-9CD5365F3016} - {A2213374-BB48-48FD-BBD4-81E6A961D866} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} - {E0580562-F8F2-4EBB-B07A-ABFC6F2C314F} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} + {A2213374-BB48-48FD-BBD4-81E6A961D866} = {5470CA36-48C3-4283-B1DB-8D168E57F2A7} + {E0580562-F8F2-4EBB-B07A-ABFC6F2C314F} = {7C235DEB-7400-470D-80AC-003A662F31F3} {CA86CF6F-5D9E-4DAC-9CCB-0F87B519E087} = {F10AA149-2626-486E-85BB-9CD5365F3016} {4A7E8F99-4265-4B66-AB07-B8FAED794DE2} = {F10AA149-2626-486E-85BB-9CD5365F3016} {B02066C3-0275-4DA9-B761-EF78FA7DB2F9} = {0440FD52-239B-40E9-9EBC-34B36F698676} {A0DBEC87-8CB7-4B8C-BD60-EE9FFBA759FB} = {A9CEE774-07BE-415D-935C-D42562C045F9} {5F21891C-72FC-4814-A2B4-3EE7E86F54C2} = {A9CEE774-07BE-415D-935C-D42562C045F9} - {F17AF2E0-E290-43A6-8695-B653FA6446EE} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} + {F17AF2E0-E290-43A6-8695-B653FA6446EE} = {7C235DEB-7400-470D-80AC-003A662F31F3} {9AFB01E8-783F-472E-90D6-F2A8AD6120FF} = {A9CEE774-07BE-415D-935C-D42562C045F9} {A285A2DC-3435-48A4-B005-D47710AA351D} = {A9CEE774-07BE-415D-935C-D42562C045F9} {B55DAA71-4958-485D-8888-E185C2104931} = {A9CEE774-07BE-415D-935C-D42562C045F9} + {5470CA36-48C3-4283-B1DB-8D168E57F2A7} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} + {7C235DEB-7400-470D-80AC-003A662F31F3} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC} + {AF0BE94D-8F47-4FA1-9101-E71699C39F00} = {7C235DEB-7400-470D-80AC-003A662F31F3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C6B33810-FA59-48A3-9DC4-F1F0312C57F6} diff --git a/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs b/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs index 55c2483..85b5a35 100644 --- a/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs +++ b/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Abp.AspNetCore.Mvc.Authorization; +using Abp; using Abp.Authorization; using Abp.Authorization.Users; using Abp.Configuration.Startup; @@ -8,6 +10,7 @@ using Abp.Domain.Uow; using Abp.Extensions; using Abp.MultiTenancy; using Abp.Notifications; +using Abp.Timing; using Abp.Web.Models; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -269,6 +272,32 @@ namespace PearAdmin.AbpTemplate.Admin.Controllers return defaultValueBuilder(); } + /// + /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers. + /// Don't use this code in production !!! + /// + /// + /// + [AbpMvcAuthorize] + public async Task TestNotification(string message = "") + { + if (message.IsNullOrEmpty()) + { + message = "This is a test notification, created at " + Clock.Now; + } + + var defaultTenantAdmin = new UserIdentifier(1, 2); + var hostAdmin = new UserIdentifier(null, 1); + + await _notificationPublisher.PublishAsync( + "App.SimpleMessage", + new MessageNotificationData(message), + severity: NotificationSeverity.Info, + userIds: new[] { defaultTenantAdmin, hostAdmin } + ); + + return Content("Sent notification: " + message); + } #endregion } } diff --git a/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj b/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj index 93e030e..b0f5bd7 100644 --- a/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj +++ b/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj @@ -30,7 +30,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs b/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs new file mode 100644 index 0000000..da77833 --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs @@ -0,0 +1,45 @@ +using Abp.AspNetCore; +using Abp.AspNetCore.SignalR; +using Abp.Hangfire; +using Abp.MailKit; +using Abp.Modules; +using Abp.Reflection.Extensions; +using Abp.Timing; +using PearAdmin.AbpTemplate.EntityFrameworkCore; +using PearAdmin.AbpTemplate.Gateway; +using PearAdmin.AbpTemplate.Timing; + +namespace PearAdmin.AbpTemplate.Api +{ + [DependsOn( + typeof(AbpTemplateApplicationModule), + typeof(AbpTemplateEntityFrameworkModule), + typeof(AbpTemplateGatewayModule), + typeof(AbpAspNetCoreModule), + typeof(AbpAspNetCoreSignalRModule), + typeof(AbpHangfireAspNetCoreModule), + typeof(AbpMailKitModule) + )] + public class AbpTemplateApiModule : AbpModule + { + public override void PreInitialize() + { + Configuration.Auditing.IsEnabledForAnonymousUsers = true; + } + + public override void Initialize() + { + IocManager.RegisterAssemblyByConvention(typeof(AbpTemplateApiModule).GetAssembly()); + } + + public override void PostInitialize() + { + IocManager.Resolve().StartupTime = Clock.Now; + } + + public override void Shutdown() + { + base.Shutdown(); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs b/src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs new file mode 100644 index 0000000..0677590 --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs @@ -0,0 +1,28 @@ +using Abp.Web.Security.AntiForgery; +using Microsoft.AspNetCore.Antiforgery; +using Microsoft.AspNetCore.Mvc; + +namespace PearAdmin.AbpTemplate.Api.Controllers +{ + public class AntiForgeryController : ControllerBase + { + private readonly IAntiforgery _antiforgery; + private readonly IAbpAntiForgeryManager _antiForgeryManager; + + public AntiForgeryController(IAntiforgery antiforgery, IAbpAntiForgeryManager antiForgeryManager) + { + _antiforgery = antiforgery; + _antiForgeryManager = antiForgeryManager; + } + + public void GetToken() + { + _antiforgery.SetCookieTokenAndHeader(HttpContext); + } + + public void SetCookie() + { + _antiForgeryManager.SetCookie(HttpContext); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs new file mode 100644 index 0000000..5ff922f --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs @@ -0,0 +1,50 @@ +using Abp; +using Abp.Extensions; +using Abp.Notifications; +using Abp.Timing; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; + +namespace PearAdmin.AbpTemplate.Api.Controllers +{ + public class HomeController : ControllerBase + { + private readonly INotificationPublisher _notificationPublisher; + + public HomeController(INotificationPublisher notificationPublisher) + { + _notificationPublisher = notificationPublisher; + } + + public IActionResult Index() + { + return Redirect("/swagger"); + } + + /// + /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers. + /// Don't use this code in production !!! + /// + /// + /// + public async Task TestNotification(string message = "") + { + if (message.IsNullOrEmpty()) + { + message = "This is a test notification, created at " + Clock.Now; + } + + var defaultTenantAdmin = new UserIdentifier(1, 2); + var hostAdmin = new UserIdentifier(null, 1); + + await _notificationPublisher.PublishAsync( + "App.SimpleMessage", + new MessageNotificationData(message), + severity: NotificationSeverity.Info, + userIds: new[] { defaultTenantAdmin, hostAdmin } + ); + + return Content("Sent notification: " + message); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Extensions/AbpBootstrapperOptionsExtension.cs b/src/PearAdmin.AbpTemplate.Api/Extensions/AbpBootstrapperOptionsExtension.cs new file mode 100644 index 0000000..823d05f --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Extensions/AbpBootstrapperOptionsExtension.cs @@ -0,0 +1,17 @@ +using Abp; +using Castle.Facilities.Logging; +using Microsoft.Extensions.Configuration; +using System; +using PearAdmin.AbpTemplate.NLog; + +namespace PearAdmin.AbpTemplate.Api.Extensions +{ + public class AbpBootstrapperOptionsExtension + { + public static Action GetOptions(IConfiguration configuration) + { + return options => options.IocManager.IocContainer + .AddFacility(f => f.UseAbpNLog(configuration.GetSection("NLog"))); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs b/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs new file mode 100644 index 0000000..8286b52 --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs @@ -0,0 +1,77 @@ +using Abp.Runtime.Security; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PearAdmin.AbpTemplate.Api.Extensions +{ + public static class AuthConfigurerExtension + { + public static void Configure(this IServiceCollection services, IConfiguration configuration) + { + if (bool.Parse(configuration["Authentication:JwtBearer:IsEnabled"])) + { + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = "JwtBearer"; + options.DefaultChallengeScheme = "JwtBearer"; + }).AddJwtBearer("JwtBearer", options => + { + options.Audience = configuration["Authentication:JwtBearer:Audience"]; + + options.TokenValidationParameters = new TokenValidationParameters + { + // The signing key must match! + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(configuration["Authentication:JwtBearer:SecurityKey"])), + + // Validate the JWT Issuer (iss) claim + ValidateIssuer = true, + ValidIssuer = configuration["Authentication:JwtBearer:Issuer"], + + // Validate the JWT Audience (aud) claim + ValidateAudience = true, + ValidAudience = configuration["Authentication:JwtBearer:Audience"], + + // Validate the token expiry + ValidateLifetime = true, + + // If you want to allow a certain amount of clock drift, set that here + ClockSkew = TimeSpan.Zero + }; + + options.Events = new JwtBearerEvents + { + OnMessageReceived = QueryStringTokenResolver + }; + }); + } + } + + /* This method is needed to authorize SignalR javascript client. + * SignalR can not send authorization header. So, we are getting it from query string as an encrypted text. */ + private static Task QueryStringTokenResolver(MessageReceivedContext context) + { + if (!context.HttpContext.Request.Path.HasValue || + !context.HttpContext.Request.Path.Value.StartsWith("/signalr")) + { + // We are just looking for signalr clients + return Task.CompletedTask; + } + + var qsAuthToken = context.HttpContext.Request.Query["enc_auth_token"].FirstOrDefault(); + if (qsAuthToken == null) + { + // Cookie value does not matches to querystring value + return Task.CompletedTask; + } + + // Set auth token from cookie + context.Token = SimpleStringCipher.Instance.Decrypt(qsAuthToken); + return Task.CompletedTask; + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs b/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs new file mode 100644 index 0000000..f1f23b9 --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using PearAdmin.AbpTemplate.Configuration; + +namespace PearAdmin.AbpTemplate.Api.Extensions +{ + public static class HostingEnvironmentExtension + { + public static IConfigurationRoot GetAppConfiguration(this IWebHostEnvironment env) + { + return AppConfigurations.Get(env.ContentRootPath, env.EnvironmentName, env.IsDevelopment()); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj new file mode 100644 index 0000000..dcb558d --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj @@ -0,0 +1,58 @@ + + + net6.0 + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + true + PearAdmin.AbpTemplate.Api.Web.Host + Exe + PearAdmin.AbpTemplate.Api.Web.Host + AbpCompanyName-PearAdmin.AbpTemplate.Api-56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 + true + true + true + + + + + + + PreserveNewest + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + Always + + + + + + + + + \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/Program.cs b/src/PearAdmin.AbpTemplate.Api/Program.cs new file mode 100644 index 0000000..72a00cf --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Program.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace PearAdmin.AbpTemplate.Api +{ + public class Program + { + public static void Main(string[] args) + { + BuildWebHost(args).Run(); + } + + public static IWebHost BuildWebHost(string[] args) + { + return WebHost.CreateDefaultBuilder(args) + .UseStartup() + .ConfigureLogging((hostingContext, logging) => + { + logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")) + .AddDebug() + .AddEventSourceLogger() + .AddFilter("System", LogLevel.Debug) + .AddFilter("Microsoft.EntityFrameworkCore.*", LogLevel.Warning) + .AddFilter("Microsoft.AspNetCore.*", LogLevel.Error); + }) + .Build(); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json b/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json new file mode 100644 index 0000000..7a5e25d --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "https://localhost:44311/", + "sslPort": 44311 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "PearAdmin.AbpTemplate.Api.Web.Host": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "https://localhost:44311/", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:44311/" + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/Startup.cs b/src/PearAdmin.AbpTemplate.Api/Startup.cs new file mode 100644 index 0000000..a56b5b1 --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Startup.cs @@ -0,0 +1,135 @@ +using Abp.AspNetCore; +using Abp.AspNetCore.Mvc.Antiforgery; +using Abp.AspNetCore.SignalR.Hubs; +using Abp.Dependency; +using Abp.Json; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Serialization; +using PearAdmin.AbpTemplate.Api.Extensions; +using PearAdmin.AbpTemplate.Identity; +using System; +using System.IO; +using System.Reflection; + +namespace PearAdmin.AbpTemplate.Api +{ + public class Startup + { + private const string _defaultCorsPolicyName = "localhost"; + + private const string _apiVersion = "v1"; + + private readonly IConfigurationRoot Configuration; + + public Startup(IWebHostEnvironment env) + { + Configuration = env.GetAppConfiguration(); + } + + public IServiceProvider ConfigureServices(IServiceCollection services) + { + #region MVC + services.AddControllersWithViews( + options => { options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute()); } + ).AddNewtonsoftJson(options => + { + options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance) + { + NamingStrategy = new CamelCaseNamingStrategy() + }; + }); + #endregion + + #region Auth + IdentityRegistrar.Register(services); + AuthConfigurerExtension.Configure(services, Configuration); + #endregion + + #region SignalR + services.AddSignalR(); + #endregion + + #region Swagger + services.AddSwaggerGen(options => + { + options.SwaggerDoc(_apiVersion, new OpenApiInfo + { + Version = _apiVersion, + Title = "PearAdmin.AbpTemplate.Api API", + Description = "PearAdmin.AbpTemplate.Api", + // uncomment if needed TermsOfService = new Uri("https://example.com/terms"), + Contact = new OpenApiContact + { + Name = "PearAdmin.AbpTemplate.Api", + Email = string.Empty, + Url = new Uri("https://twitter.com/aspboilerplate"), + }, + License = new OpenApiLicense + { + Name = "MIT License", + Url = new Uri("https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/LICENSE"), + } + }); + options.DocInclusionPredicate((docName, description) => true); + + // Define the BearerAuth scheme that's in use + options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme() + { + Description = + "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", + Name = "Authorization", + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey + }); + + //add summaries to swagger + bool canShowSummaries = _appConfiguration.GetValue("Swagger:ShowSummaries"); + if (canShowSummaries) + { + var hostXmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var hostXmlPath = Path.Combine(AppContext.BaseDirectory, hostXmlFile); + options.IncludeXmlComments(hostXmlPath); + + var applicationXml = $"PearAdmin.AbpTemplate.Api.Application.xml"; + var applicationXmlPath = Path.Combine(AppContext.BaseDirectory, applicationXml); + options.IncludeXmlComments(applicationXmlPath); + + var webCoreXmlFile = $"PearAdmin.AbpTemplate.Api.Web.Core.xml"; + var webCoreXmlPath = Path.Combine(AppContext.BaseDirectory, webCoreXmlFile); + options.IncludeXmlComments(webCoreXmlPath); + } + }); + #endregion + + return services.AddAbp(AbpBootstrapperOptionsExtension.GetOptions(Configuration)); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + { + app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); + app.UseStaticFiles(); + app.UseRouting(); + app.UseAuthentication(); + app.UseAuthorization(); + app.UseAbpRequestLocalization(); + app.UseEndpoints(endpoints => + { + endpoints.MapHub("/signalr"); + endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}"); + }); + app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; }); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"PearAdmin.AbpTemplate.Api API {_apiVersion}"); + options.IndexStream = () => Assembly.GetExecutingAssembly() + .GetManifestResourceStream("PearAdmin.AbpTemplate.Api.Web.Host.wwwroot.swagger.ui.index.html"); + options.DisplayRequestDuration(); + }); + } + } +} diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json b/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json new file mode 100644 index 0000000..20f82ee --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json @@ -0,0 +1,9 @@ +{ + "ConnectionStrings": { + "Default": "Server=10.0.75.1; Database=PearAdmin.AbpTemplate.ApiDb; User=sa; Password=123qwe;" + }, + "App": { + "ServerRootAddress": "http://localhost:9902/", + "CorsOrigins": "http://localhost:9902" + } +} \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.json b/src/PearAdmin.AbpTemplate.Api/appsettings.json new file mode 100644 index 0000000..e64752f --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.json @@ -0,0 +1,28 @@ +{ + "ConnectionStrings": { + "Default": "Server=localhost; Database=PearAdmin.AbpTemplate.ApiDb; Trusted_Connection=True; TrustServerCertificate=True;" + }, + "App": { + "ServerRootAddress": "https://localhost:44311/", + "ClientRootAddress": "http://localhost:4200/", + "CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081,http://localhost:3000" + }, + "Authentication": { + "JwtBearer": { + "IsEnabled": "true", + "SecurityKey": "PearAdmin.AbpTemplate.Api_635AD546DE4B46C6", + "Issuer": "PearAdmin.AbpTemplate.Api", + "Audience": "PearAdmin.AbpTemplate.Api" + } + }, + "Kestrel": { + "Endpoints": { + "Http": { + "Url": "https://localhost:44311/" + } + } + }, + "Swagger": { + "ShowSummaries": false + } +} \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js new file mode 100644 index 0000000..9957fdf --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js @@ -0,0 +1,117 @@ +var abp = abp || {}; +(function () { + + /* Application paths *****************************************/ + + // Current application root path (including virtual directory if exists). + abp.appPath = abp.appPath || '/'; + + /* AUTHORIZATION **********************************************/ + // Implements Authorization API that simplifies usage of authorization scripts generated by Abp. + + abp.auth = abp.auth || {}; + + abp.auth.tokenCookieName = 'Abp.AuthToken'; + abp.auth.tokenHeaderName = 'Authorization'; + + abp.auth.setToken = function (authToken, expireDate) { + abp.utils.setCookieValue(abp.auth.tokenCookieName, authToken, expireDate, abp.appPath); + }; + + abp.auth.getToken = function () { + return abp.utils.getCookieValue(abp.auth.tokenCookieName); + } + + abp.auth.clearToken = function () { + abp.auth.setToken(); + } + + /* UTILS ***************************************************/ + + abp.utils = abp.utils || {}; + + /** + * Sets a cookie value for given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @param {string} value + * @param {Date} expireDate (optional). If not specified the cookie will expire at the end of session. + * @param {string} path (optional) + */ + abp.utils.setCookieValue = function (key, value, expireDate, path) { + var cookieValue = encodeURIComponent(key) + '='; + + if (value) { + cookieValue = cookieValue + encodeURIComponent(value); + } + + if (expireDate) { + cookieValue = cookieValue + "; expires=" + expireDate.toUTCString(); + } + + if (path) { + cookieValue = cookieValue + "; path=" + path; + } + + document.cookie = cookieValue; + }; + + /** + * Gets a cookie with given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @returns {string} Cookie value or null + */ + abp.utils.getCookieValue = function (key) { + var equalities = document.cookie.split('; '); + for (var i = 0; i < equalities.length; i++) { + if (!equalities[i]) { + continue; + } + + var splitted = equalities[i].split('='); + if (splitted.length != 2) { + continue; + } + + if (decodeURIComponent(splitted[0]) === key) { + return decodeURIComponent(splitted[1] || ''); + } + } + + return null; + }; + + /** + * Deletes cookie for given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @param {string} path (optional) + */ + abp.utils.deleteCookie = function (key, path) { + var cookieValue = encodeURIComponent(key) + '='; + + cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); + + if (path) { + cookieValue = cookieValue + "; path=" + path; + } + + document.cookie = cookieValue; + } + + /* SECURITY ***************************************/ + abp.security = abp.security || {}; + abp.security.antiForgery = abp.security.antiForgery || {}; + + abp.security.antiForgery.tokenCookieName = 'XSRF-TOKEN'; + abp.security.antiForgery.tokenHeaderName = 'X-XSRF-TOKEN'; + + abp.security.antiForgery.getToken = function () { + return abp.utils.getCookieValue(abp.security.antiForgery.tokenCookieName); + }; + +})(); diff --git a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js new file mode 100644 index 0000000..26bfeec --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js @@ -0,0 +1,214 @@ +var abp = abp || {}; +(function () { + + /* Swagger */ + + abp.swagger = abp.swagger || {}; + + abp.swagger.addAuthToken = function () { + var authToken = abp.auth.getToken(); + if (!authToken) { + return false; + } + + var cookieAuth = new SwaggerClient.ApiKeyAuthorization(abp.auth.tokenHeaderName, 'Bearer ' + authToken, 'header'); + swaggerUi.api.clientAuthorizations.add('bearerAuth', cookieAuth); + return true; + } + + abp.swagger.addCsrfToken = function () { + var csrfToken = abp.security.antiForgery.getToken(); + if (!csrfToken) { + return false; + } + var csrfCookieAuth = new SwaggerClient.ApiKeyAuthorization(abp.security.antiForgery.tokenHeaderName, csrfToken, 'header'); + swaggerUi.api.clientAuthorizations.add(abp.security.antiForgery.tokenHeaderName, csrfCookieAuth); + return true; + } + + function addAntiForgeryTokenToXhr(xhr) { + var antiForgeryToken = abp.security.antiForgery.getToken(); + if (antiForgeryToken) { + xhr.setRequestHeader(abp.security.antiForgery.tokenHeaderName, antiForgeryToken); + } + } + + function loginUserInternal(tenantId, callback) { + var usernameOrEmailAddress = document.getElementById('userName').value; + if (!usernameOrEmailAddress) { + alert('Username or Email Address is required, please try with a valid value !'); + return false; + } + + var password = document.getElementById('password').value; + if (!password) { + alert('Password is required, please try with a valid value !'); + return false; + } + + var xhr = new XMLHttpRequest(); + + xhr.onreadystatechange = function () { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + var responseJSON = JSON.parse(xhr.responseText); + var result = responseJSON.result; + var expireDate = new Date(Date.now() + (result.expireInSeconds * 1000)); + abp.auth.setToken(result.accessToken, expireDate); + callback(); + } else { + alert('Login failed !'); + } + } + }; + + xhr.open('POST', '/api/TokenAuth/Authenticate', true); + xhr.setRequestHeader('Abp.TenantId', tenantId); + xhr.setRequestHeader('Content-type', 'application/json'); + addAntiForgeryTokenToXhr(xhr); + xhr.send( + JSON.stringify( + { usernameOrEmailAddress: usernameOrEmailAddress, password: password } + ) + ); + }; + + abp.swagger.login = function (callback) { + //Get TenantId first + var tenancyName = document.getElementById('tenancyName').value; + + if (tenancyName) { + var xhrTenancyName = new XMLHttpRequest(); + xhrTenancyName.onreadystatechange = function () { + if (xhrTenancyName.readyState === XMLHttpRequest.DONE && xhrTenancyName.status === 200) { + var responseJSON = JSON.parse(xhrTenancyName.responseText); + var result = responseJSON.result; + if (result.state === 1) { // Tenant exists and active. + loginUserInternal(result.tenantId, callback); // Login for tenant + } else { + alert('There is no such tenant or tenant is not active !'); + } + } + }; + + xhrTenancyName.open('POST', '/api/services/app/Account/IsTenantAvailable', true); + xhrTenancyName.setRequestHeader('Content-type', 'application/json'); + addAntiForgeryTokenToXhr(xhrTenancyName); + xhrTenancyName.send( + JSON.stringify({ tenancyName: tenancyName }) + ); + } else { + loginUserInternal(null, callback); // Login for host + } + }; + + abp.swagger.logout = function () { + abp.auth.clearToken(); + } + + abp.swagger.closeAuthDialog = function () { + if (document.getElementById('abp-auth-dialog')) { + document.getElementsByClassName("swagger-ui")[1].removeChild(document.getElementById('abp-auth-dialog')); + } + } + + abp.swagger.openAuthDialog = function (loginCallback) { + abp.swagger.closeAuthDialog(); + + var abpAuthDialog = document.createElement('div'); + abpAuthDialog.className = 'dialog-ux'; + abpAuthDialog.id = 'abp-auth-dialog'; + + document.getElementsByClassName("swagger-ui")[1].appendChild(abpAuthDialog); + + // -- backdrop-ux + var backdropUx = document.createElement('div'); + backdropUx.className = 'backdrop-ux'; + abpAuthDialog.appendChild(backdropUx); + + // -- modal-ux + var modalUx = document.createElement('div'); + modalUx.className = 'modal-ux'; + abpAuthDialog.appendChild(modalUx); + + // -- -- modal-dialog-ux + var modalDialogUx = document.createElement('div'); + modalDialogUx.className = 'modal-dialog-ux'; + modalUx.appendChild(modalDialogUx); + + // -- -- -- modal-ux-inner + var modalUxInner = document.createElement('div'); + modalUxInner.className = 'modal-ux-inner'; + modalDialogUx.appendChild(modalUxInner); + + // -- -- -- -- modal-ux-header + var modalUxHeader = document.createElement('div'); + modalUxHeader.className = 'modal-ux-header'; + modalUxInner.appendChild(modalUxHeader); + + var modalHeader = document.createElement('h3'); + modalHeader.innerText = 'Authorize'; + modalUxHeader.appendChild(modalHeader); + + // -- -- -- -- modal-ux-content + var modalUxContent = document.createElement('div'); + modalUxContent.className = 'modal-ux-content'; + modalUxInner.appendChild(modalUxContent); + + modalUxContent.onkeydown = function (e) { + if (e.keyCode === 13) { + //try to login when user presses enter on authorize modal + abp.swagger.login(loginCallback); + } + }; + + //Inputs + createInput(modalUxContent, 'tenancyName', 'Tenancy Name (Leave empty for Host)'); + createInput(modalUxContent, 'userName', 'Username or email address'); + createInput(modalUxContent, 'password', 'Password', 'password'); + + //Buttons + var authBtnWrapper = document.createElement('div'); + authBtnWrapper.className = 'auth-btn-wrapper'; + modalUxContent.appendChild(authBtnWrapper); + + //Close button + var closeButton = document.createElement('button'); + closeButton.className = 'btn modal-btn auth btn-done button'; + closeButton.innerText = 'Close'; + closeButton.style.marginRight = '5px'; + closeButton.onclick = abp.swagger.closeAuthDialog; + authBtnWrapper.appendChild(closeButton); + + //Authorize button + var authorizeButton = document.createElement('button'); + authorizeButton.className = 'btn modal-btn auth authorize button'; + authorizeButton.innerText = 'Login'; + authorizeButton.onclick = function() { + abp.swagger.login(loginCallback); + }; + authBtnWrapper.appendChild(authorizeButton); + } + + function createInput(container, id, title, type) { + var wrapper = document.createElement('div'); + wrapper.className = 'wrapper'; + container.appendChild(wrapper); + + var label = document.createElement('label'); + label.innerText = title; + wrapper.appendChild(label); + + var section = document.createElement('section'); + section.className = 'block-tablet col-10-tablet block-desktop col-10-desktop'; + wrapper.appendChild(section); + + var input = document.createElement('input'); + input.id = id; + input.type = type ? type : 'text'; + input.style.width = '100%'; + + section.appendChild(input); + } + +})(); \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html new file mode 100644 index 0000000..8c699c1 --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html @@ -0,0 +1,146 @@ + + + + + + %(DocumentTitle) + + + + + + %(HeadContent) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + -- Gitee From dc4241204a3c0fe6528d3e30c627e31661abe446 Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 09:38:18 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Api=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .../PearAdmin.AbpTemplate.Admin.csproj | 12 ++-- .../Properties/launchSettings.json | 15 ----- .../AbpTemplateApiModule.cs | 24 ++++++++ .../Controllers/AntiForgeryController.cs | 28 --------- .../Controllers/HomeController.cs | 3 +- .../Extensions/AuthConfigurerExtension.cs | 4 +- .../Extensions/HostingEnvironmentExtension.cs | 1 + .../PearAdmin.AbpTemplate.Api.csproj | 33 +++------- src/PearAdmin.AbpTemplate.Api/Program.cs | 1 - .../Properties/launchSettings.json | 25 ++------ src/PearAdmin.AbpTemplate.Api/Startup.cs | 47 ++++++--------- .../appsettings.json | 60 +++++++++++++++---- 13 files changed, 117 insertions(+), 138 deletions(-) delete mode 100644 src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs diff --git a/.gitignore b/.gitignore index 1b2bff5..be7d6be 100644 --- a/.gitignore +++ b/.gitignore @@ -251,4 +251,4 @@ paket-files/ .idea/ *.sln.iml /.vs -/src/PearAdmin.AbpTemplate.Admin/App_Data/Logs +**/App_Data/Logs diff --git a/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj b/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj index b0f5bd7..80713bf 100644 --- a/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj +++ b/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj @@ -1,12 +1,9 @@  + - PearAdmin.AbpTemplate.Admin - Exe - PearAdmin.AbpTemplate.Admin - PearAdmin-AbpTemplate-56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 - PearAdmin.AbpTemplate.Admin net6.0 - $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + PearAdmin.AbpTemplate.Admin + 56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 true true true @@ -14,6 +11,7 @@ false true + @@ -21,6 +19,7 @@ + @@ -38,4 +37,5 @@ + \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Admin/Properties/launchSettings.json b/src/PearAdmin.AbpTemplate.Admin/Properties/launchSettings.json index e0fcdf7..413b4b7 100644 --- a/src/PearAdmin.AbpTemplate.Admin/Properties/launchSettings.json +++ b/src/PearAdmin.AbpTemplate.Admin/Properties/launchSettings.json @@ -1,20 +1,5 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:62114/", - "sslPort": 0 - } - }, "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "PearAdmin.AbpTemplate.Admin": { "commandName": "Project", "launchBrowser": true, diff --git a/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs b/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs index da77833..125a69c 100644 --- a/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs +++ b/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs @@ -1,10 +1,15 @@ using Abp.AspNetCore; +using Abp.AspNetCore.Configuration; using Abp.AspNetCore.SignalR; using Abp.Hangfire; using Abp.MailKit; using Abp.Modules; using Abp.Reflection.Extensions; using Abp.Timing; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.Extensions.Configuration; +using PearAdmin.AbpTemplate.Api.Extensions; using PearAdmin.AbpTemplate.EntityFrameworkCore; using PearAdmin.AbpTemplate.Gateway; using PearAdmin.AbpTemplate.Timing; @@ -22,9 +27,26 @@ namespace PearAdmin.AbpTemplate.Api )] public class AbpTemplateApiModule : AbpModule { + private readonly IWebHostEnvironment _env; + private readonly IConfigurationRoot _appConfiguration; + + public AbpTemplateApiModule(IWebHostEnvironment env) + { + _env = env; + _appConfiguration = env.GetAppConfiguration(); + } + public override void PreInitialize() { Configuration.Auditing.IsEnabledForAnonymousUsers = true; + + // 链接字符串设置 + Configuration.DefaultNameOrConnectionString = _appConfiguration.GetConnectionString(AbpTemplateCoreConsts.ConnectionStringName); + + Configuration.Modules.AbpAspNetCore() + .CreateControllersForAppServices( + typeof(AbpTemplateApiModule).GetAssembly() + ); } public override void Initialize() @@ -35,6 +57,8 @@ namespace PearAdmin.AbpTemplate.Api public override void PostInitialize() { IocManager.Resolve().StartupTime = Clock.Now; + IocManager.Resolve() + .AddApplicationPartsIfNotAddedBefore(typeof(AbpTemplateApiModule).Assembly); } public override void Shutdown() diff --git a/src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs b/src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs deleted file mode 100644 index 0677590..0000000 --- a/src/PearAdmin.AbpTemplate.Api/Controllers/AntiForgeryController.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Abp.Web.Security.AntiForgery; -using Microsoft.AspNetCore.Antiforgery; -using Microsoft.AspNetCore.Mvc; - -namespace PearAdmin.AbpTemplate.Api.Controllers -{ - public class AntiForgeryController : ControllerBase - { - private readonly IAntiforgery _antiforgery; - private readonly IAbpAntiForgeryManager _antiForgeryManager; - - public AntiForgeryController(IAntiforgery antiforgery, IAbpAntiForgeryManager antiForgeryManager) - { - _antiforgery = antiforgery; - _antiForgeryManager = antiForgeryManager; - } - - public void GetToken() - { - _antiforgery.SetCookieTokenAndHeader(HttpContext); - } - - public void SetCookie() - { - _antiForgeryManager.SetCookie(HttpContext); - } - } -} diff --git a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs index 5ff922f..ddac680 100644 --- a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs +++ b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs @@ -1,4 +1,5 @@ using Abp; +using Abp.AspNetCore.Mvc.Controllers; using Abp.Extensions; using Abp.Notifications; using Abp.Timing; @@ -7,7 +8,7 @@ using System.Threading.Tasks; namespace PearAdmin.AbpTemplate.Api.Controllers { - public class HomeController : ControllerBase + public class HomeController : AbpController { private readonly INotificationPublisher _notificationPublisher; diff --git a/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs b/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs index 8286b52..6d328f6 100644 --- a/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs +++ b/src/PearAdmin.AbpTemplate.Api/Extensions/AuthConfigurerExtension.cs @@ -1,6 +1,8 @@ using Abp.Runtime.Security; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Tokens; using System; using System.Linq; using System.Text; @@ -10,7 +12,7 @@ namespace PearAdmin.AbpTemplate.Api.Extensions { public static class AuthConfigurerExtension { - public static void Configure(this IServiceCollection services, IConfiguration configuration) + public static void AuthConfigure(this IServiceCollection services, IConfiguration configuration) { if (bool.Parse(configuration["Authentication:JwtBearer:IsEnabled"])) { diff --git a/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs b/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs index f1f23b9..902b2da 100644 --- a/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs +++ b/src/PearAdmin.AbpTemplate.Api/Extensions/HostingEnvironmentExtension.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using PearAdmin.AbpTemplate.Configuration; namespace PearAdmin.AbpTemplate.Api.Extensions diff --git a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj index dcb558d..60eee57 100644 --- a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj +++ b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj @@ -1,28 +1,10 @@  + net6.0 - $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; - true - PearAdmin.AbpTemplate.Api.Web.Host - Exe - PearAdmin.AbpTemplate.Api.Web.Host - AbpCompanyName-PearAdmin.AbpTemplate.Api-56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 - true - true - true + 56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 - - - - - - PreserveNewest - PreserveNewest - - - PreserveNewest - - + @@ -35,14 +17,17 @@ - - all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + diff --git a/src/PearAdmin.AbpTemplate.Api/Program.cs b/src/PearAdmin.AbpTemplate.Api/Program.cs index 72a00cf..788b342 100644 --- a/src/PearAdmin.AbpTemplate.Api/Program.cs +++ b/src/PearAdmin.AbpTemplate.Api/Program.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace PearAdmin.AbpTemplate.Api diff --git a/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json b/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json index 7a5e25d..f8a7958 100644 --- a/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json +++ b/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json @@ -1,28 +1,15 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "https://localhost:44311/", - "sslPort": 44311 - } - }, + "$schema": "https://json.schemastore.org/launchsettings.json", "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "PearAdmin.AbpTemplate.Api.Web.Host": { + "PearAdmin.AbpTemplate.Api": { "commandName": "Project", + "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "https://localhost:44311/", + "launchUrl": "swagger/index.html", + "applicationUrl": "https://localhost:6001;http://localhost:6000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:44311/" + } } } } diff --git a/src/PearAdmin.AbpTemplate.Api/Startup.cs b/src/PearAdmin.AbpTemplate.Api/Startup.cs index a56b5b1..8ae0466 100644 --- a/src/PearAdmin.AbpTemplate.Api/Startup.cs +++ b/src/PearAdmin.AbpTemplate.Api/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; using Newtonsoft.Json.Serialization; using PearAdmin.AbpTemplate.Api.Extensions; using PearAdmin.AbpTemplate.Identity; @@ -19,10 +20,7 @@ namespace PearAdmin.AbpTemplate.Api { public class Startup { - private const string _defaultCorsPolicyName = "localhost"; - private const string _apiVersion = "v1"; - private readonly IConfigurationRoot Configuration; public Startup(IWebHostEnvironment env) @@ -32,26 +30,21 @@ namespace PearAdmin.AbpTemplate.Api public IServiceProvider ConfigureServices(IServiceCollection services) { - #region MVC - services.AddControllersWithViews( - options => { options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute()); } - ).AddNewtonsoftJson(options => + services.AddControllers(options => { - options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance) - { - NamingStrategy = new CamelCaseNamingStrategy() - }; - }); - #endregion + options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute()); + }).AddNewtonsoftJson(options => + { + options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance) + { + NamingStrategy = new CamelCaseNamingStrategy() + }; + }); - #region Auth IdentityRegistrar.Register(services); - AuthConfigurerExtension.Configure(services, Configuration); - #endregion + services.AuthConfigure(Configuration); - #region SignalR services.AddSignalR(); - #endregion #region Swagger services.AddSwaggerGen(options => @@ -59,12 +52,12 @@ namespace PearAdmin.AbpTemplate.Api options.SwaggerDoc(_apiVersion, new OpenApiInfo { Version = _apiVersion, - Title = "PearAdmin.AbpTemplate.Api API", - Description = "PearAdmin.AbpTemplate.Api", + Title = "PearAdmin AbpTemplate API", + Description = "PearAdmin AbpTemplate", // uncomment if needed TermsOfService = new Uri("https://example.com/terms"), Contact = new OpenApiContact { - Name = "PearAdmin.AbpTemplate.Api", + Name = "PearAdmin AbpTemplate", Email = string.Empty, Url = new Uri("https://twitter.com/aspboilerplate"), }, @@ -87,20 +80,16 @@ namespace PearAdmin.AbpTemplate.Api }); //add summaries to swagger - bool canShowSummaries = _appConfiguration.GetValue("Swagger:ShowSummaries"); + bool canShowSummaries = Configuration.GetValue("Swagger:ShowSummaries"); if (canShowSummaries) { var hostXmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var hostXmlPath = Path.Combine(AppContext.BaseDirectory, hostXmlFile); options.IncludeXmlComments(hostXmlPath); - var applicationXml = $"PearAdmin.AbpTemplate.Api.Application.xml"; + var applicationXml = $"PearAdmin AbpTemplate.Application.xml"; var applicationXmlPath = Path.Combine(AppContext.BaseDirectory, applicationXml); options.IncludeXmlComments(applicationXmlPath); - - var webCoreXmlFile = $"PearAdmin.AbpTemplate.Api.Web.Core.xml"; - var webCoreXmlPath = Path.Combine(AppContext.BaseDirectory, webCoreXmlFile); - options.IncludeXmlComments(webCoreXmlPath); } }); #endregion @@ -125,9 +114,9 @@ namespace PearAdmin.AbpTemplate.Api app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; }); app.UseSwaggerUI(options => { - options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"PearAdmin.AbpTemplate.Api API {_apiVersion}"); + options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"PearAdmin AbpTemplate API {_apiVersion}"); options.IndexStream = () => Assembly.GetExecutingAssembly() - .GetManifestResourceStream("PearAdmin.AbpTemplate.Api.Web.Host.wwwroot.swagger.ui.index.html"); + .GetManifestResourceStream("PearAdmin.AbpTemplate.Api.wwwroot.swagger.ui.index.html"); options.DisplayRequestDuration(); }); } diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.json b/src/PearAdmin.AbpTemplate.Api/appsettings.json index e64752f..2b03e85 100644 --- a/src/PearAdmin.AbpTemplate.Api/appsettings.json +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.json @@ -1,11 +1,6 @@ { "ConnectionStrings": { - "Default": "Server=localhost; Database=PearAdmin.AbpTemplate.ApiDb; Trusted_Connection=True; TrustServerCertificate=True;" - }, - "App": { - "ServerRootAddress": "https://localhost:44311/", - "ClientRootAddress": "http://localhost:4200/", - "CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081,http://localhost:3000" + "Default": "server=106.53.127.56;database=pearadminabpdb;uid=root;pwd=StarCity@2023!;" }, "Authentication": { "JwtBearer": { @@ -15,14 +10,53 @@ "Audience": "PearAdmin.AbpTemplate.Api" } }, - "Kestrel": { - "Endpoints": { - "Http": { - "Url": "https://localhost:44311/" - } - } - }, "Swagger": { "ShowSummaries": false + }, + "NLog": { + "autoReload": true, + "throwConfigExceptions": true, + "internalLogLevel": "Info", + "internalLogFile": "App_Data/Logs/nlogs.txt", + "extensions": [ + { + "NLog.Web.AspNetCore": { + "assembly": "NLog.Web.AspNetCore" + } + } + ], + "targets": { + "allfile": { + "maxArchiveDays": 3, + "maxArchiveFiles": 3, + "type": "File", + "fileName": "App_Data/Logs/nlog-all-${shortdate}.log", + "layout": "${longdate}||${level}||${logger}||${message}||${exception:format=ToString:innerFormat=ToString:maxInnerExceptionLevel=10:separator=\\r\\n}||end" + }, + "ownFile-web": { + "maxArchiveDays": 3, + "maxArchiveFiles": 3, + "type": "File", + "fileName": "App_Data/Logs/nlog-my-${shortdate}.log", + "layout": "${longdate}||${level}||${logger}||${message}||${exception:format=ToString:innerFormat=ToString:maxInnerExceptionLevel=10:separator=\\r\\n}||end" + } + }, + "rules": [ + { + "logger": "*", + "minLevel": "Trace", + "writeTo": "allfile" + }, + { + "logger": "*", + "minLevel": "Trace", + "writeTo": "ownFile-web" + }, + { + "logger": "Microsoft.*", + "maxLevel": "Info", + "final": true + } + ] } } \ No newline at end of file -- Gitee From dcd78f9faf5f268832bf09c851a3fae8968def16 Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 13:03:27 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbpTemplateApiModule.cs | 4 ++-- .../Controllers/HomeController.cs | 4 ++++ .../PearAdmin.AbpTemplate.Api.csproj | 18 ++++++++++++++++++ src/PearAdmin.AbpTemplate.Api/Startup.cs | 8 +++++++- .../Accounts/IAccountAppService.cs | 3 ++- .../Permissions/IPermissionAppService.cs | 3 ++- .../Authorization/Roles/IRoleAppService.cs | 3 ++- .../Authorization/Users/IUserAppService.cs | 3 ++- .../Common/Sessions/ISessionAppService.cs | 3 ++- ...ditDto.cs => HostGeneralSettingsEditDto.cs} | 2 +- .../HostSettings/Dto/HostSettingsEditDto.cs | 2 +- .../HostSettings/HostSettingsAppService.cs | 6 +++--- .../HostSettings/IHostSettingsAppService.cs | 3 ++- .../Monitoring/Auditing/AuditLogAppService.cs | 2 +- .../Exporting/AuditLogListExcelExporter.cs | 2 +- .../Exporting/IAuditLogListExcelExporter.cs | 5 +++-- .../Monitoring/Auditing/IAuditLogAppService.cs | 3 ++- .../Loggings/IWebSiteLogAppService.cs | 3 ++- .../Editions/IEditionAppService.cs | 3 ++- ...tDto.cs => TenantGeneralSettingsEditDto.cs} | 2 +- .../Dto/TenantSettingsEditDto.cs | 2 +- .../ITenantSettingsAppService.cs | 3 ++- .../TenantSettings/TenantSettingsAppService.cs | 4 ++-- .../MultiTenancy/Tenants/ITenantAppService.cs | 3 ++- .../Notifications/INotificationAppService.cs | 3 ++- .../IOrganizationUnitAppService.cs | 3 ++- .../IDataDictionaryAppService.cs | 3 ++- .../Social/Chat/IChatAppService.cs | 3 ++- .../Friendships/IFriendshipAppService.cs | 3 ++- .../DailyTasks/IDailyTaskAppService.cs | 3 ++- 30 files changed, 79 insertions(+), 33 deletions(-) rename src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/{GeneralSettingsEditDto.cs => HostGeneralSettingsEditDto.cs} (87%) rename src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/{GeneralSettingsEditDto.cs => TenantGeneralSettingsEditDto.cs} (87%) diff --git a/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs b/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs index 125a69c..71081c7 100644 --- a/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs +++ b/src/PearAdmin.AbpTemplate.Api/AbpTemplateApiModule.cs @@ -45,7 +45,7 @@ namespace PearAdmin.AbpTemplate.Api Configuration.Modules.AbpAspNetCore() .CreateControllersForAppServices( - typeof(AbpTemplateApiModule).GetAssembly() + typeof(AbpTemplateApplicationModule).GetAssembly() ); } @@ -58,7 +58,7 @@ namespace PearAdmin.AbpTemplate.Api { IocManager.Resolve().StartupTime = Clock.Now; IocManager.Resolve() - .AddApplicationPartsIfNotAddedBefore(typeof(AbpTemplateApiModule).Assembly); + .AddApplicationPartsIfNotAddedBefore(typeof(AbpTemplateApiModule).Assembly); } public override void Shutdown() diff --git a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs index ddac680..1c88a48 100644 --- a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs +++ b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs @@ -8,6 +8,8 @@ using System.Threading.Tasks; namespace PearAdmin.AbpTemplate.Api.Controllers { + [ApiController] + [Route("[controller]")] public class HomeController : AbpController { private readonly INotificationPublisher _notificationPublisher; @@ -17,6 +19,7 @@ namespace PearAdmin.AbpTemplate.Api.Controllers _notificationPublisher = notificationPublisher; } + [HttpGet] public IActionResult Index() { return Redirect("/swagger"); @@ -28,6 +31,7 @@ namespace PearAdmin.AbpTemplate.Api.Controllers /// /// /// + [HttpGet("TestNotification")] public async Task TestNotification(string message = "") { if (message.IsNullOrEmpty()) diff --git a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj index 60eee57..048430c 100644 --- a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj +++ b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj @@ -2,7 +2,16 @@ net6.0 + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + true + PearAdmin.AbpTemplate.Api + Exe + PearAdmin.AbpTemplate.Web.Host 56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 + true + true + 7.2 + false @@ -29,15 +38,24 @@ + Always + + + + + PreserveNewest + + + \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/Startup.cs b/src/PearAdmin.AbpTemplate.Api/Startup.cs index 8ae0466..484458f 100644 --- a/src/PearAdmin.AbpTemplate.Api/Startup.cs +++ b/src/PearAdmin.AbpTemplate.Api/Startup.cs @@ -30,7 +30,8 @@ namespace PearAdmin.AbpTemplate.Api public IServiceProvider ConfigureServices(IServiceCollection services) { - services.AddControllers(options => + #region MVC + services.AddControllersWithViews(options => { options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute()); }).AddNewtonsoftJson(options => @@ -40,11 +41,16 @@ namespace PearAdmin.AbpTemplate.Api NamingStrategy = new CamelCaseNamingStrategy() }; }); + #endregion + #region Identity IdentityRegistrar.Register(services); services.AuthConfigure(Configuration); + #endregion + #region SignalR services.AddSignalR(); + #endregion #region Swagger services.AddSwaggerGen(options => diff --git a/src/PearAdmin.AbpTemplate.Application/Authorization/Accounts/IAccountAppService.cs b/src/PearAdmin.AbpTemplate.Application/Authorization/Accounts/IAccountAppService.cs index ebb9cd3..1bccfaa 100644 --- a/src/PearAdmin.AbpTemplate.Application/Authorization/Accounts/IAccountAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Authorization/Accounts/IAccountAppService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Abp.Application.Services; +using Abp.Dependency; using PearAdmin.AbpTemplate.Authorization.Accounts.Dto; namespace PearAdmin.AbpTemplate.Authorization.Accounts { - public interface IAccountAppService : IApplicationService + public interface IAccountAppService : IApplicationService, ITransientDependency { Task IsTenantAvailable(IsTenantAvailableInput input); diff --git a/src/PearAdmin.AbpTemplate.Application/Authorization/Permissions/IPermissionAppService.cs b/src/PearAdmin.AbpTemplate.Application/Authorization/Permissions/IPermissionAppService.cs index b1c884d..1c04aeb 100644 --- a/src/PearAdmin.AbpTemplate.Application/Authorization/Permissions/IPermissionAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Authorization/Permissions/IPermissionAppService.cs @@ -1,10 +1,11 @@ using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Authorization.Permissions.Dto; namespace PearAdmin.AbpTemplate.Authorization.Permissions { - public interface IPermissionAppService : IApplicationService + public interface IPermissionAppService : IApplicationService, ITransientDependency { /// /// 分页筛选获取权限树结构(树形结构数据) diff --git a/src/PearAdmin.AbpTemplate.Application/Authorization/Roles/IRoleAppService.cs b/src/PearAdmin.AbpTemplate.Application/Authorization/Roles/IRoleAppService.cs index cf7c82f..8c3d505 100644 --- a/src/PearAdmin.AbpTemplate.Application/Authorization/Roles/IRoleAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Authorization/Roles/IRoleAppService.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Authorization.Roles.Dto; namespace PearAdmin.AbpTemplate.Authorization.Roles @@ -9,7 +10,7 @@ namespace PearAdmin.AbpTemplate.Authorization.Roles /// /// 角色应用服务 /// - public interface IRoleAppService : IApplicationService + public interface IRoleAppService : IApplicationService, ITransientDependency { /// /// 获取所有角色 diff --git a/src/PearAdmin.AbpTemplate.Application/Authorization/Users/IUserAppService.cs b/src/PearAdmin.AbpTemplate.Application/Authorization/Users/IUserAppService.cs index 00fa40f..dd78bf5 100644 --- a/src/PearAdmin.AbpTemplate.Application/Authorization/Users/IUserAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Authorization/Users/IUserAppService.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Authorization.Users.Dto; namespace PearAdmin.AbpTemplate.Authorization.Users @@ -9,7 +10,7 @@ namespace PearAdmin.AbpTemplate.Authorization.Users /// /// 用户应用服务接口 /// - public interface IUserAppService : IApplicationService + public interface IUserAppService : IApplicationService, ITransientDependency { /// /// 分页获取用户列表 diff --git a/src/PearAdmin.AbpTemplate.Application/Common/Sessions/ISessionAppService.cs b/src/PearAdmin.AbpTemplate.Application/Common/Sessions/ISessionAppService.cs index 1910850..2b51237 100644 --- a/src/PearAdmin.AbpTemplate.Application/Common/Sessions/ISessionAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Common/Sessions/ISessionAppService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Abp.Application.Services; +using Abp.Dependency; using PearAdmin.AbpTemplate.Sessions.Dto; namespace PearAdmin.AbpTemplate.Sessions { - public interface ISessionAppService : IApplicationService + public interface ISessionAppService : IApplicationService, ITransientDependency { Task GetCurrentLoginInformations(); } diff --git a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/GeneralSettingsEditDto.cs b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostGeneralSettingsEditDto.cs similarity index 87% rename from src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/GeneralSettingsEditDto.cs rename to src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostGeneralSettingsEditDto.cs index 9282579..eb8766b 100644 --- a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/GeneralSettingsEditDto.cs +++ b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostGeneralSettingsEditDto.cs @@ -1,6 +1,6 @@ namespace PearAdmin.AbpTemplate.Host.HostSettings.Dto { - public class GeneralSettingsEditDto + public class HostGeneralSettingsEditDto { public string Timezone { get; set; } diff --git a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostSettingsEditDto.cs b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostSettingsEditDto.cs index 425f499..2268d89 100644 --- a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostSettingsEditDto.cs +++ b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/Dto/HostSettingsEditDto.cs @@ -5,7 +5,7 @@ namespace PearAdmin.AbpTemplate.Host.HostSettings.Dto public class HostSettingsEditDto { [Required] - public GeneralSettingsEditDto General { get; set; } + public HostGeneralSettingsEditDto General { get; set; } [Required] public HostManagementSettingsEditDto HostManagement { get; set; } diff --git a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/HostSettingsAppService.cs b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/HostSettingsAppService.cs index 03bade8..0d3bcc1 100644 --- a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/HostSettingsAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/HostSettingsAppService.cs @@ -33,10 +33,10 @@ namespace PearAdmin.AbpTemplate.Host.HostSettings }; } - private async Task GetGeneralSettingsAsync() + private async Task GetGeneralSettingsAsync() { var timezone = await SettingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone); - var settings = new GeneralSettingsEditDto + var settings = new HostGeneralSettingsEditDto { Timezone = timezone, TimezoneForComparison = timezone @@ -72,7 +72,7 @@ namespace PearAdmin.AbpTemplate.Host.HostSettings await UpdateHostManagementAsync(input.HostManagement); } - private async Task UpdateGeneralSettingsAsync(GeneralSettingsEditDto settings) + private async Task UpdateGeneralSettingsAsync(HostGeneralSettingsEditDto settings) { if (Clock.SupportsMultipleTimezone) { diff --git a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/IHostSettingsAppService.cs b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/IHostSettingsAppService.cs index 1809284..b8d89a8 100644 --- a/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/IHostSettingsAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Host/HostSettings/IHostSettingsAppService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Abp.Application.Services; +using Abp.Dependency; using PearAdmin.AbpTemplate.Host.HostSettings.Dto; namespace PearAdmin.AbpTemplate.Host.HostSettings { - public interface IHostSettingsAppService : IApplicationService + public interface IHostSettingsAppService : IApplicationService, ITransientDependency { Task GetAllSettings(); diff --git a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/AuditLogAppService.cs b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/AuditLogAppService.cs index 0915af0..dee680e 100644 --- a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/AuditLogAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/AuditLogAppService.cs @@ -197,7 +197,7 @@ namespace PearAdmin.AbpTemplate.Auditing var entityChangeListDtos = ConvertToEntityChangeListDtos(entityChanges); - return _auditLogListExcelExporter.ExportToFile(entityChangeListDtos); + return _auditLogListExcelExporter.BatchExportToFile(entityChangeListDtos); } public async Task> GetEntityPropertyChanges(long entityChangeId) diff --git a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/AuditLogListExcelExporter.cs b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/AuditLogListExcelExporter.cs index ad32f7b..0e326b0 100644 --- a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/AuditLogListExcelExporter.cs +++ b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/AuditLogListExcelExporter.cs @@ -78,7 +78,7 @@ namespace PearAdmin.AbpTemplate.Auditing.Exporting }); } - public FileDto ExportToFile(List entityChangeListDtos) + public FileDto BatchExportToFile(List entityChangeListDtos) { return CreateExcelPackage( "DetailedLogs.xlsx", diff --git a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/IAuditLogListExcelExporter.cs b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/IAuditLogListExcelExporter.cs index 57edf20..f05fd35 100644 --- a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/IAuditLogListExcelExporter.cs +++ b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/Exporting/IAuditLogListExcelExporter.cs @@ -1,13 +1,14 @@ using System.Collections.Generic; +using Abp.Dependency; using PearAdmin.AbpTemplate.Auditing.Dto; using PearAdmin.AbpTemplate.CommonDto; namespace PearAdmin.AbpTemplate.Auditing.Exporting { - public interface IAuditLogListExcelExporter + public interface IAuditLogListExcelExporter: ITransientDependency { FileDto ExportToFile(List auditLogListDtos); - FileDto ExportToFile(List entityChangeListDtos); + FileDto BatchExportToFile(List entityChangeListDtos); } } diff --git a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/IAuditLogAppService.cs b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/IAuditLogAppService.cs index dfad23e..128360a 100644 --- a/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/IAuditLogAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Monitoring/Auditing/IAuditLogAppService.cs @@ -2,12 +2,13 @@ using System.Threading.Tasks; using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Auditing.Dto; using PearAdmin.AbpTemplate.CommonDto; namespace PearAdmin.AbpTemplate.Auditing { - public interface IAuditLogAppService : IApplicationService + public interface IAuditLogAppService : IApplicationService, ITransientDependency { /// /// 分页、筛选审计日志列表 diff --git a/src/PearAdmin.AbpTemplate.Application/Monitoring/Loggings/IWebSiteLogAppService.cs b/src/PearAdmin.AbpTemplate.Application/Monitoring/Loggings/IWebSiteLogAppService.cs index 896fff6..ba0a95f 100644 --- a/src/PearAdmin.AbpTemplate.Application/Monitoring/Loggings/IWebSiteLogAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Monitoring/Loggings/IWebSiteLogAppService.cs @@ -1,4 +1,5 @@ using Abp.Application.Services; +using Abp.Dependency; using PearAdmin.AbpTemplate.CommonDto; using PearAdmin.AbpTemplate.Loggings.Dto; @@ -7,7 +8,7 @@ namespace PearAdmin.AbpTemplate.Loggings /// /// 网站运行日志应用层服务 /// - public interface IWebSiteLogAppService : IApplicationService + public interface IWebSiteLogAppService : IApplicationService, ITransientDependency { /// /// 获取最近的一个日志文件 diff --git a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Editions/IEditionAppService.cs b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Editions/IEditionAppService.cs index fe5216d..8ed33a7 100644 --- a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Editions/IEditionAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Editions/IEditionAppService.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.MultiTenancy.Editions.Dto; namespace PearAdmin.AbpTemplate.MultiTenancy.Editions @@ -8,7 +9,7 @@ namespace PearAdmin.AbpTemplate.MultiTenancy.Editions /// /// 版本管理应用服务接口 /// - public interface IEditionAppService : IApplicationService + public interface IEditionAppService : IApplicationService, ITransientDependency { /// /// 获取全部版本列表 diff --git a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/GeneralSettingsEditDto.cs b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantGeneralSettingsEditDto.cs similarity index 87% rename from src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/GeneralSettingsEditDto.cs rename to src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantGeneralSettingsEditDto.cs index 89a320f..90e9fcf 100644 --- a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/GeneralSettingsEditDto.cs +++ b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantGeneralSettingsEditDto.cs @@ -1,6 +1,6 @@ namespace PearAdmin.AbpTemplate.MultiTenancy.TenantSetting.Dto { - public class GeneralSettingsEditDto + public class TenantGeneralSettingsEditDto { public string Timezone { get; set; } diff --git a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantSettingsEditDto.cs b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantSettingsEditDto.cs index b216116..7b540a3 100644 --- a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantSettingsEditDto.cs +++ b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/Dto/TenantSettingsEditDto.cs @@ -2,7 +2,7 @@ { public class TenantSettingsEditDto { - public GeneralSettingsEditDto General { get; set; } + public TenantGeneralSettingsEditDto General { get; set; } public TenantEmailSettingsEditDto Email { get; set; } diff --git a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/ITenantSettingsAppService.cs b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/ITenantSettingsAppService.cs index 4cfd56a..a1946b2 100644 --- a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/ITenantSettingsAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/ITenantSettingsAppService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Abp.Application.Services; +using Abp.Dependency; using PearAdmin.AbpTemplate.MultiTenancy.TenantSetting.Dto; namespace PearAdmin.AbpTemplate.MultiTenancy.TenantSetting { - public interface ITenantSettingsAppService : IApplicationService + public interface ITenantSettingsAppService : IApplicationService, ITransientDependency { Task GetAllSettings(); diff --git a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/TenantSettingsAppService.cs b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/TenantSettingsAppService.cs index a83b76c..1d45bb8 100644 --- a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/TenantSettingsAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/TenantSettings/TenantSettingsAppService.cs @@ -84,9 +84,9 @@ namespace PearAdmin.AbpTemplate.MultiTenancy.TenantSetting }; } - private async Task GetGeneralSettingsAsync() + private async Task GetGeneralSettingsAsync() { - var settings = new GeneralSettingsEditDto(); + var settings = new TenantGeneralSettingsEditDto(); if (Clock.SupportsMultipleTimezone) { diff --git a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Tenants/ITenantAppService.cs b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Tenants/ITenantAppService.cs index 6540389..13e183f 100644 --- a/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Tenants/ITenantAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/MultiTenancy/Tenants/ITenantAppService.cs @@ -1,5 +1,6 @@ using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.MultiTenancy.Tenants.Dto; using System.Threading.Tasks; @@ -8,7 +9,7 @@ namespace PearAdmin.AbpTemplate.MultiTenancy.Tenants /// /// 租户应用服务 /// - public interface ITenantAppService : IApplicationService + public interface ITenantAppService : IApplicationService, ITransientDependency { /// /// 获取全部租户 diff --git a/src/PearAdmin.AbpTemplate.Application/Notifications/INotificationAppService.cs b/src/PearAdmin.AbpTemplate.Application/Notifications/INotificationAppService.cs index 82d373f..c26a18d 100644 --- a/src/PearAdmin.AbpTemplate.Application/Notifications/INotificationAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Notifications/INotificationAppService.cs @@ -1,5 +1,6 @@ using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Notifications.Dto; using System; using System.Collections.Generic; @@ -10,7 +11,7 @@ namespace PearAdmin.AbpTemplate.Notifications /// /// 消息应用层服务 /// - public interface INotificationAppService : IApplicationService + public interface INotificationAppService : IApplicationService, ITransientDependency { /// /// 分页获取消息 diff --git a/src/PearAdmin.AbpTemplate.Application/Organizations/IOrganizationUnitAppService.cs b/src/PearAdmin.AbpTemplate.Application/Organizations/IOrganizationUnitAppService.cs index 3c46b00..8511cb1 100644 --- a/src/PearAdmin.AbpTemplate.Application/Organizations/IOrganizationUnitAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Organizations/IOrganizationUnitAppService.cs @@ -3,13 +3,14 @@ using Abp.Application.Services.Dto; using System.Collections.Generic; using System.Threading.Tasks; using PearAdmin.AbpTemplate.Organizations.Dto; +using Abp.Dependency; namespace PearAdmin.AbpTemplate.Organizations { /// /// 组织机构应用服务 /// - public interface IOrganizationUnitAppService : IApplicationService + public interface IOrganizationUnitAppService : IApplicationService, ITransientDependency { /// /// 获取组织机构(树形结构数据) diff --git a/src/PearAdmin.AbpTemplate.Application/Resource/DataDictionaries/IDataDictionaryAppService.cs b/src/PearAdmin.AbpTemplate.Application/Resource/DataDictionaries/IDataDictionaryAppService.cs index d6d1e95..43a3ee1 100644 --- a/src/PearAdmin.AbpTemplate.Application/Resource/DataDictionaries/IDataDictionaryAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Resource/DataDictionaries/IDataDictionaryAppService.cs @@ -1,5 +1,6 @@ using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Resource.DataDictionaries.Dto; using System.Collections.Generic; using System.Threading.Tasks; @@ -9,7 +10,7 @@ namespace PearAdmin.AbpTemplate.Resource.DataDictionaries /// /// 数据字典应用服务接口 /// - public interface IDataDictionaryAppService : IApplicationService + public interface IDataDictionaryAppService : IApplicationService, ITransientDependency { /// /// 获取数据字典集合 diff --git a/src/PearAdmin.AbpTemplate.Application/Social/Chat/IChatAppService.cs b/src/PearAdmin.AbpTemplate.Application/Social/Chat/IChatAppService.cs index 5a7e9f3..bb91def 100644 --- a/src/PearAdmin.AbpTemplate.Application/Social/Chat/IChatAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Social/Chat/IChatAppService.cs @@ -1,11 +1,12 @@ using System.Threading.Tasks; using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.Social.Chat.Dto; namespace PearAdmin.AbpTemplate.Social.Chat { - public interface IChatAppService : IApplicationService + public interface IChatAppService : IApplicationService, ITransientDependency { Task> GetAllChatUser(); diff --git a/src/PearAdmin.AbpTemplate.Application/Social/Friendships/IFriendshipAppService.cs b/src/PearAdmin.AbpTemplate.Application/Social/Friendships/IFriendshipAppService.cs index 9ba0a17..cd1690d 100644 --- a/src/PearAdmin.AbpTemplate.Application/Social/Friendships/IFriendshipAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/Social/Friendships/IFriendshipAppService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Abp.Application.Services; +using Abp.Dependency; using PearAdmin.AbpTemplate.Social.Friendships.Dto; namespace PearAdmin.AbpTemplate.Social.Friendships { - public interface IFriendshipAppService : IApplicationService + public interface IFriendshipAppService : IApplicationService, ITransientDependency { Task CreateFriendshipRequest(CreateFriendshipRequestInput input); diff --git a/src/PearAdmin.AbpTemplate.Application/TaskCenter/DailyTasks/IDailyTaskAppService.cs b/src/PearAdmin.AbpTemplate.Application/TaskCenter/DailyTasks/IDailyTaskAppService.cs index b3dab85..7ee90f1 100644 --- a/src/PearAdmin.AbpTemplate.Application/TaskCenter/DailyTasks/IDailyTaskAppService.cs +++ b/src/PearAdmin.AbpTemplate.Application/TaskCenter/DailyTasks/IDailyTaskAppService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Abp.Application.Services; using Abp.Application.Services.Dto; +using Abp.Dependency; using PearAdmin.AbpTemplate.TaskCenter.DailyTasks.Dto; namespace PearAdmin.AbpTemplate.TaskCenter.DailyTasks @@ -10,7 +11,7 @@ namespace PearAdmin.AbpTemplate.TaskCenter.DailyTasks /// /// 日常任务应用服务 /// - public interface IDailyTaskAppService : IApplicationService + public interface IDailyTaskAppService : IApplicationService, ITransientDependency { /// /// 获取日常任务列表 -- Gitee From 92f31b3f19ca31cfc5895675870da267a295ecec Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 13:11:13 +0800 Subject: [PATCH 4/8] Rollback --- .../Controllers/AccountController.cs | 38 ++----------------- .../PearAdmin.AbpTemplate.Admin.csproj | 8 +++- .../appsettings.json | 2 +- 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs b/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs index 85b5a35..5df74f1 100644 --- a/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs +++ b/src/PearAdmin.AbpTemplate.Admin/Controllers/AccountController.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Abp.AspNetCore.Mvc.Authorization; -using Abp; -using Abp.Authorization; +using Abp.Authorization; using Abp.Authorization.Users; using Abp.Configuration.Startup; using Abp.Domain.Uow; using Abp.Extensions; using Abp.MultiTenancy; using Abp.Notifications; -using Abp.Timing; using Abp.Web.Models; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -21,6 +15,9 @@ using PearAdmin.AbpTemplate.ExternalAuth; using PearAdmin.AbpTemplate.Identity; using PearAdmin.AbpTemplate.MultiTenancy; using PearAdmin.AbpTemplate.Sessions; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace PearAdmin.AbpTemplate.Admin.Controllers { @@ -271,33 +268,6 @@ namespace PearAdmin.AbpTemplate.Admin.Controllers return defaultValueBuilder(); } - - /// - /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers. - /// Don't use this code in production !!! - /// - /// - /// - [AbpMvcAuthorize] - public async Task TestNotification(string message = "") - { - if (message.IsNullOrEmpty()) - { - message = "This is a test notification, created at " + Clock.Now; - } - - var defaultTenantAdmin = new UserIdentifier(1, 2); - var hostAdmin = new UserIdentifier(null, 1); - - await _notificationPublisher.PublishAsync( - "App.SimpleMessage", - new MessageNotificationData(message), - severity: NotificationSeverity.Info, - userIds: new[] { defaultTenantAdmin, hostAdmin } - ); - - return Content("Sent notification: " + message); - } #endregion } } diff --git a/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj b/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj index 80713bf..0ee5ccc 100644 --- a/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj +++ b/src/PearAdmin.AbpTemplate.Admin/PearAdmin.AbpTemplate.Admin.csproj @@ -1,9 +1,13 @@  - net6.0 + PearAdmin.AbpTemplate.Admin + Exe + PearAdmin.AbpTemplate.Admin + PearAdmin-AbpTemplate-56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 PearAdmin.AbpTemplate.Admin - 56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 + net6.0 + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; true true true diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.json b/src/PearAdmin.AbpTemplate.Api/appsettings.json index 2b03e85..6c5d855 100644 --- a/src/PearAdmin.AbpTemplate.Api/appsettings.json +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "Default": "server=106.53.127.56;database=pearadminabpdb;uid=root;pwd=StarCity@2023!;" + "Default": "" }, "Authentication": { "JwtBearer": { -- Gitee From bc6491ced6c6e1e0662b06bbb1408e1ae48806b5 Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 13:17:29 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=95=B4=E7=90=86csproj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PearAdmin.AbpTemplate.Api.csproj | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj index 048430c..a82b571 100644 --- a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj +++ b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj @@ -6,11 +6,10 @@ true PearAdmin.AbpTemplate.Api Exe - PearAdmin.AbpTemplate.Web.Host - 56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 + PearAdmin.AbpTemplate.Api + PearAdmin-AbpTemplate-56C2EF2F-ABD6-4EFC-AAF2-2E81C34E8FB1 true true - 7.2 false @@ -35,6 +34,13 @@ + + + + + + + @@ -45,13 +51,6 @@ - - - - - - - PreserveNewest -- Gitee From 09c475c71ba0b0b06084d586bc241f758eeb8391 Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 13:58:44 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4swagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PearAdmin.AbpTemplate.Api.csproj | 16 -- src/PearAdmin.AbpTemplate.Api/Startup.cs | 24 +- .../wwwroot/swagger/ui/abp.js | 117 ---------- .../wwwroot/swagger/ui/abp.swagger.js | 214 ------------------ .../wwwroot/swagger/ui/index.html | 146 ------------ 5 files changed, 2 insertions(+), 515 deletions(-) delete mode 100644 src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js delete mode 100644 src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js delete mode 100644 src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html diff --git a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj index a82b571..64afd8b 100644 --- a/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj +++ b/src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj @@ -41,20 +41,4 @@ - - - - - - - Always - - - - - - PreserveNewest - - - \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/Startup.cs b/src/PearAdmin.AbpTemplate.Api/Startup.cs index 484458f..bd55c06 100644 --- a/src/PearAdmin.AbpTemplate.Api/Startup.cs +++ b/src/PearAdmin.AbpTemplate.Api/Startup.cs @@ -13,8 +13,6 @@ using Newtonsoft.Json.Serialization; using PearAdmin.AbpTemplate.Api.Extensions; using PearAdmin.AbpTemplate.Identity; using System; -using System.IO; -using System.Reflection; namespace PearAdmin.AbpTemplate.Api { @@ -74,29 +72,13 @@ namespace PearAdmin.AbpTemplate.Api } }); options.DocInclusionPredicate((docName, description) => true); - - // Define the BearerAuth scheme that's in use - options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme() + options.AddSecurityDefinition("BearerAuth", new OpenApiSecurityScheme() { - Description = - "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", + Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); - - //add summaries to swagger - bool canShowSummaries = Configuration.GetValue("Swagger:ShowSummaries"); - if (canShowSummaries) - { - var hostXmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; - var hostXmlPath = Path.Combine(AppContext.BaseDirectory, hostXmlFile); - options.IncludeXmlComments(hostXmlPath); - - var applicationXml = $"PearAdmin AbpTemplate.Application.xml"; - var applicationXmlPath = Path.Combine(AppContext.BaseDirectory, applicationXml); - options.IncludeXmlComments(applicationXmlPath); - } }); #endregion @@ -121,8 +103,6 @@ namespace PearAdmin.AbpTemplate.Api app.UseSwaggerUI(options => { options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"PearAdmin AbpTemplate API {_apiVersion}"); - options.IndexStream = () => Assembly.GetExecutingAssembly() - .GetManifestResourceStream("PearAdmin.AbpTemplate.Api.wwwroot.swagger.ui.index.html"); options.DisplayRequestDuration(); }); } diff --git a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js deleted file mode 100644 index 9957fdf..0000000 --- a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.js +++ /dev/null @@ -1,117 +0,0 @@ -var abp = abp || {}; -(function () { - - /* Application paths *****************************************/ - - // Current application root path (including virtual directory if exists). - abp.appPath = abp.appPath || '/'; - - /* AUTHORIZATION **********************************************/ - // Implements Authorization API that simplifies usage of authorization scripts generated by Abp. - - abp.auth = abp.auth || {}; - - abp.auth.tokenCookieName = 'Abp.AuthToken'; - abp.auth.tokenHeaderName = 'Authorization'; - - abp.auth.setToken = function (authToken, expireDate) { - abp.utils.setCookieValue(abp.auth.tokenCookieName, authToken, expireDate, abp.appPath); - }; - - abp.auth.getToken = function () { - return abp.utils.getCookieValue(abp.auth.tokenCookieName); - } - - abp.auth.clearToken = function () { - abp.auth.setToken(); - } - - /* UTILS ***************************************************/ - - abp.utils = abp.utils || {}; - - /** - * Sets a cookie value for given key. - * This is a simple implementation created to be used by ABP. - * Please use a complete cookie library if you need. - * @param {string} key - * @param {string} value - * @param {Date} expireDate (optional). If not specified the cookie will expire at the end of session. - * @param {string} path (optional) - */ - abp.utils.setCookieValue = function (key, value, expireDate, path) { - var cookieValue = encodeURIComponent(key) + '='; - - if (value) { - cookieValue = cookieValue + encodeURIComponent(value); - } - - if (expireDate) { - cookieValue = cookieValue + "; expires=" + expireDate.toUTCString(); - } - - if (path) { - cookieValue = cookieValue + "; path=" + path; - } - - document.cookie = cookieValue; - }; - - /** - * Gets a cookie with given key. - * This is a simple implementation created to be used by ABP. - * Please use a complete cookie library if you need. - * @param {string} key - * @returns {string} Cookie value or null - */ - abp.utils.getCookieValue = function (key) { - var equalities = document.cookie.split('; '); - for (var i = 0; i < equalities.length; i++) { - if (!equalities[i]) { - continue; - } - - var splitted = equalities[i].split('='); - if (splitted.length != 2) { - continue; - } - - if (decodeURIComponent(splitted[0]) === key) { - return decodeURIComponent(splitted[1] || ''); - } - } - - return null; - }; - - /** - * Deletes cookie for given key. - * This is a simple implementation created to be used by ABP. - * Please use a complete cookie library if you need. - * @param {string} key - * @param {string} path (optional) - */ - abp.utils.deleteCookie = function (key, path) { - var cookieValue = encodeURIComponent(key) + '='; - - cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); - - if (path) { - cookieValue = cookieValue + "; path=" + path; - } - - document.cookie = cookieValue; - } - - /* SECURITY ***************************************/ - abp.security = abp.security || {}; - abp.security.antiForgery = abp.security.antiForgery || {}; - - abp.security.antiForgery.tokenCookieName = 'XSRF-TOKEN'; - abp.security.antiForgery.tokenHeaderName = 'X-XSRF-TOKEN'; - - abp.security.antiForgery.getToken = function () { - return abp.utils.getCookieValue(abp.security.antiForgery.tokenCookieName); - }; - -})(); diff --git a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js deleted file mode 100644 index 26bfeec..0000000 --- a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/abp.swagger.js +++ /dev/null @@ -1,214 +0,0 @@ -var abp = abp || {}; -(function () { - - /* Swagger */ - - abp.swagger = abp.swagger || {}; - - abp.swagger.addAuthToken = function () { - var authToken = abp.auth.getToken(); - if (!authToken) { - return false; - } - - var cookieAuth = new SwaggerClient.ApiKeyAuthorization(abp.auth.tokenHeaderName, 'Bearer ' + authToken, 'header'); - swaggerUi.api.clientAuthorizations.add('bearerAuth', cookieAuth); - return true; - } - - abp.swagger.addCsrfToken = function () { - var csrfToken = abp.security.antiForgery.getToken(); - if (!csrfToken) { - return false; - } - var csrfCookieAuth = new SwaggerClient.ApiKeyAuthorization(abp.security.antiForgery.tokenHeaderName, csrfToken, 'header'); - swaggerUi.api.clientAuthorizations.add(abp.security.antiForgery.tokenHeaderName, csrfCookieAuth); - return true; - } - - function addAntiForgeryTokenToXhr(xhr) { - var antiForgeryToken = abp.security.antiForgery.getToken(); - if (antiForgeryToken) { - xhr.setRequestHeader(abp.security.antiForgery.tokenHeaderName, antiForgeryToken); - } - } - - function loginUserInternal(tenantId, callback) { - var usernameOrEmailAddress = document.getElementById('userName').value; - if (!usernameOrEmailAddress) { - alert('Username or Email Address is required, please try with a valid value !'); - return false; - } - - var password = document.getElementById('password').value; - if (!password) { - alert('Password is required, please try with a valid value !'); - return false; - } - - var xhr = new XMLHttpRequest(); - - xhr.onreadystatechange = function () { - if (xhr.readyState === XMLHttpRequest.DONE) { - if (xhr.status === 200) { - var responseJSON = JSON.parse(xhr.responseText); - var result = responseJSON.result; - var expireDate = new Date(Date.now() + (result.expireInSeconds * 1000)); - abp.auth.setToken(result.accessToken, expireDate); - callback(); - } else { - alert('Login failed !'); - } - } - }; - - xhr.open('POST', '/api/TokenAuth/Authenticate', true); - xhr.setRequestHeader('Abp.TenantId', tenantId); - xhr.setRequestHeader('Content-type', 'application/json'); - addAntiForgeryTokenToXhr(xhr); - xhr.send( - JSON.stringify( - { usernameOrEmailAddress: usernameOrEmailAddress, password: password } - ) - ); - }; - - abp.swagger.login = function (callback) { - //Get TenantId first - var tenancyName = document.getElementById('tenancyName').value; - - if (tenancyName) { - var xhrTenancyName = new XMLHttpRequest(); - xhrTenancyName.onreadystatechange = function () { - if (xhrTenancyName.readyState === XMLHttpRequest.DONE && xhrTenancyName.status === 200) { - var responseJSON = JSON.parse(xhrTenancyName.responseText); - var result = responseJSON.result; - if (result.state === 1) { // Tenant exists and active. - loginUserInternal(result.tenantId, callback); // Login for tenant - } else { - alert('There is no such tenant or tenant is not active !'); - } - } - }; - - xhrTenancyName.open('POST', '/api/services/app/Account/IsTenantAvailable', true); - xhrTenancyName.setRequestHeader('Content-type', 'application/json'); - addAntiForgeryTokenToXhr(xhrTenancyName); - xhrTenancyName.send( - JSON.stringify({ tenancyName: tenancyName }) - ); - } else { - loginUserInternal(null, callback); // Login for host - } - }; - - abp.swagger.logout = function () { - abp.auth.clearToken(); - } - - abp.swagger.closeAuthDialog = function () { - if (document.getElementById('abp-auth-dialog')) { - document.getElementsByClassName("swagger-ui")[1].removeChild(document.getElementById('abp-auth-dialog')); - } - } - - abp.swagger.openAuthDialog = function (loginCallback) { - abp.swagger.closeAuthDialog(); - - var abpAuthDialog = document.createElement('div'); - abpAuthDialog.className = 'dialog-ux'; - abpAuthDialog.id = 'abp-auth-dialog'; - - document.getElementsByClassName("swagger-ui")[1].appendChild(abpAuthDialog); - - // -- backdrop-ux - var backdropUx = document.createElement('div'); - backdropUx.className = 'backdrop-ux'; - abpAuthDialog.appendChild(backdropUx); - - // -- modal-ux - var modalUx = document.createElement('div'); - modalUx.className = 'modal-ux'; - abpAuthDialog.appendChild(modalUx); - - // -- -- modal-dialog-ux - var modalDialogUx = document.createElement('div'); - modalDialogUx.className = 'modal-dialog-ux'; - modalUx.appendChild(modalDialogUx); - - // -- -- -- modal-ux-inner - var modalUxInner = document.createElement('div'); - modalUxInner.className = 'modal-ux-inner'; - modalDialogUx.appendChild(modalUxInner); - - // -- -- -- -- modal-ux-header - var modalUxHeader = document.createElement('div'); - modalUxHeader.className = 'modal-ux-header'; - modalUxInner.appendChild(modalUxHeader); - - var modalHeader = document.createElement('h3'); - modalHeader.innerText = 'Authorize'; - modalUxHeader.appendChild(modalHeader); - - // -- -- -- -- modal-ux-content - var modalUxContent = document.createElement('div'); - modalUxContent.className = 'modal-ux-content'; - modalUxInner.appendChild(modalUxContent); - - modalUxContent.onkeydown = function (e) { - if (e.keyCode === 13) { - //try to login when user presses enter on authorize modal - abp.swagger.login(loginCallback); - } - }; - - //Inputs - createInput(modalUxContent, 'tenancyName', 'Tenancy Name (Leave empty for Host)'); - createInput(modalUxContent, 'userName', 'Username or email address'); - createInput(modalUxContent, 'password', 'Password', 'password'); - - //Buttons - var authBtnWrapper = document.createElement('div'); - authBtnWrapper.className = 'auth-btn-wrapper'; - modalUxContent.appendChild(authBtnWrapper); - - //Close button - var closeButton = document.createElement('button'); - closeButton.className = 'btn modal-btn auth btn-done button'; - closeButton.innerText = 'Close'; - closeButton.style.marginRight = '5px'; - closeButton.onclick = abp.swagger.closeAuthDialog; - authBtnWrapper.appendChild(closeButton); - - //Authorize button - var authorizeButton = document.createElement('button'); - authorizeButton.className = 'btn modal-btn auth authorize button'; - authorizeButton.innerText = 'Login'; - authorizeButton.onclick = function() { - abp.swagger.login(loginCallback); - }; - authBtnWrapper.appendChild(authorizeButton); - } - - function createInput(container, id, title, type) { - var wrapper = document.createElement('div'); - wrapper.className = 'wrapper'; - container.appendChild(wrapper); - - var label = document.createElement('label'); - label.innerText = title; - wrapper.appendChild(label); - - var section = document.createElement('section'); - section.className = 'block-tablet col-10-tablet block-desktop col-10-desktop'; - wrapper.appendChild(section); - - var input = document.createElement('input'); - input.id = id; - input.type = type ? type : 'text'; - input.style.width = '100%'; - - section.appendChild(input); - } - -})(); \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html b/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html deleted file mode 100644 index 8c699c1..0000000 --- a/src/PearAdmin.AbpTemplate.Api/wwwroot/swagger/ui/index.html +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - %(DocumentTitle) - - - - - - %(HeadContent) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -- Gitee From e72bde754a5ad31fc23ba1cc691077895093f60e Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 14:27:14 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=95=B4=E7=90=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appsettings.Development.json | 2 +- ...gs.Stage.json => appsettings.Staging.json} | 0 .../Controllers/HomeController.cs | 39 ------------------- .../Properties/launchSettings.json | 1 - .../appsettings.Development.json | 5 +++ .../appsettings.Production.json | 5 +++ .../appsettings.Staging.json | 6 +-- .../appsettings.json | 3 -- 8 files changed, 12 insertions(+), 49 deletions(-) rename src/PearAdmin.AbpTemplate.Admin/{appsettings.Stage.json => appsettings.Staging.json} (100%) create mode 100644 src/PearAdmin.AbpTemplate.Api/appsettings.Development.json create mode 100644 src/PearAdmin.AbpTemplate.Api/appsettings.Production.json diff --git a/src/PearAdmin.AbpTemplate.Admin/appsettings.Development.json b/src/PearAdmin.AbpTemplate.Admin/appsettings.Development.json index 23e02a2..96289c0 100644 --- a/src/PearAdmin.AbpTemplate.Admin/appsettings.Development.json +++ b/src/PearAdmin.AbpTemplate.Admin/appsettings.Development.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "Default": "Server=cdb-9qxfgkob.gz.tencentcdb.com; Database=PearAdminAbpDemoDb;Port=10143;charset=utf8;uid=pearadmindemodb;pwd=pearadmindemodb@test;", + "Default": "", "Redis": "" }, "App": { diff --git a/src/PearAdmin.AbpTemplate.Admin/appsettings.Stage.json b/src/PearAdmin.AbpTemplate.Admin/appsettings.Staging.json similarity index 100% rename from src/PearAdmin.AbpTemplate.Admin/appsettings.Stage.json rename to src/PearAdmin.AbpTemplate.Admin/appsettings.Staging.json diff --git a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs index 1c88a48..71e003f 100644 --- a/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs +++ b/src/PearAdmin.AbpTemplate.Api/Controllers/HomeController.cs @@ -1,10 +1,5 @@ -using Abp; using Abp.AspNetCore.Mvc.Controllers; -using Abp.Extensions; -using Abp.Notifications; -using Abp.Timing; using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; namespace PearAdmin.AbpTemplate.Api.Controllers { @@ -12,44 +7,10 @@ namespace PearAdmin.AbpTemplate.Api.Controllers [Route("[controller]")] public class HomeController : AbpController { - private readonly INotificationPublisher _notificationPublisher; - - public HomeController(INotificationPublisher notificationPublisher) - { - _notificationPublisher = notificationPublisher; - } - [HttpGet] public IActionResult Index() { return Redirect("/swagger"); } - - /// - /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers. - /// Don't use this code in production !!! - /// - /// - /// - [HttpGet("TestNotification")] - public async Task TestNotification(string message = "") - { - if (message.IsNullOrEmpty()) - { - message = "This is a test notification, created at " + Clock.Now; - } - - var defaultTenantAdmin = new UserIdentifier(1, 2); - var hostAdmin = new UserIdentifier(null, 1); - - await _notificationPublisher.PublishAsync( - "App.SimpleMessage", - new MessageNotificationData(message), - severity: NotificationSeverity.Info, - userIds: new[] { defaultTenantAdmin, hostAdmin } - ); - - return Content("Sent notification: " + message); - } } } diff --git a/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json b/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json index f8a7958..73d4a27 100644 --- a/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json +++ b/src/PearAdmin.AbpTemplate.Api/Properties/launchSettings.json @@ -1,5 +1,4 @@ { - "$schema": "https://json.schemastore.org/launchsettings.json", "profiles": { "PearAdmin.AbpTemplate.Api": { "commandName": "Project", diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.Development.json b/src/PearAdmin.AbpTemplate.Api/appsettings.Development.json new file mode 100644 index 0000000..1f4f80f --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.Development.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "Default": "" + } +} \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.Production.json b/src/PearAdmin.AbpTemplate.Api/appsettings.Production.json new file mode 100644 index 0000000..1f4f80f --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.Production.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "Default": "" + } +} \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json b/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json index 20f82ee..1f4f80f 100644 --- a/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.Staging.json @@ -1,9 +1,5 @@ { "ConnectionStrings": { - "Default": "Server=10.0.75.1; Database=PearAdmin.AbpTemplate.ApiDb; User=sa; Password=123qwe;" - }, - "App": { - "ServerRootAddress": "http://localhost:9902/", - "CorsOrigins": "http://localhost:9902" + "Default": "" } } \ No newline at end of file diff --git a/src/PearAdmin.AbpTemplate.Api/appsettings.json b/src/PearAdmin.AbpTemplate.Api/appsettings.json index 6c5d855..0e1ffe8 100644 --- a/src/PearAdmin.AbpTemplate.Api/appsettings.json +++ b/src/PearAdmin.AbpTemplate.Api/appsettings.json @@ -10,9 +10,6 @@ "Audience": "PearAdmin.AbpTemplate.Api" } }, - "Swagger": { - "ShowSummaries": false - }, "NLog": { "autoReload": true, "throwConfigExceptions": true, -- Gitee From a18e86e9d5e3e5d42e9b75dceae809a6a76646af Mon Sep 17 00:00:00 2001 From: sassassin <530521314@qq.com> Date: Sun, 16 Jul 2023 14:31:05 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PearAdmin.AbpTemplate.Api/Dockerfile | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/PearAdmin.AbpTemplate.Api/Dockerfile diff --git a/src/PearAdmin.AbpTemplate.Api/Dockerfile b/src/PearAdmin.AbpTemplate.Api/Dockerfile new file mode 100644 index 0000000..0ea236c --- /dev/null +++ b/src/PearAdmin.AbpTemplate.Api/Dockerfile @@ -0,0 +1,33 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 + +RUN apt-get update -y && apt-get install -y libgdiplus && apt-get clean && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo 'Asia/Shanghai' >/etc/timezone + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj", "src/PearAdmin.AbpTemplate.Api/"] +COPY ["module/PearAdmin.AbpTemplate.NLog/PearAdmin.AbpTemplate.NLog.csproj", "module/PearAdmin.AbpTemplate.NLog/"] +COPY ["src/PearAdmin.AbpTemplate.Application/PearAdmin.AbpTemplate.Application.csproj", "src/PearAdmin.AbpTemplate.Application/"] +COPY ["src/PearAdmin.AbpTemplate.Core/PearAdmin.AbpTemplate.Core.csproj", "src/PearAdmin.AbpTemplate.Core/"] +COPY ["tool/PearAdmin.AbpTemplate.Shared/PearAdmin.AbpTemplate.Shared.csproj", "tool/PearAdmin.AbpTemplate.Shared/"] +COPY ["module/PearAdmin.AbpTemplate.Storage.Minio/PearAdmin.AbpTemplate.Storage.Minio.csproj", "module/PearAdmin.AbpTemplate.Storage.Minio/"] +COPY ["module/PearAdmin.AbpTemplate.Storage/PearAdmin.AbpTemplate.Storage.csproj", "module/PearAdmin.AbpTemplate.Storage/"] +COPY ["src/PearAdmin.AbpTemplate.EntityFrameworkCore/PearAdmin.AbpTemplate.EntityFrameworkCore.csproj", "src/PearAdmin.AbpTemplate.EntityFrameworkCore/"] +COPY ["src/PearAdmin.AbpTemplate.Gateway/PearAdmin.AbpTemplate.Gateway.csproj", "src/PearAdmin.AbpTemplate.Gateway/"] +RUN dotnet restore "src/PearAdmin.AbpTemplate.Api/PearAdmin.AbpTemplate.Api.csproj" +COPY . . +WORKDIR "/src/src/PearAdmin.AbpTemplate.Api" +RUN dotnet build "PearAdmin.AbpTemplate.Api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "PearAdmin.AbpTemplate.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "PearAdmin.AbpTemplate.Api.dll"] \ No newline at end of file -- Gitee