diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs b/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs index 4fe290a9..5c952413 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs @@ -62,7 +62,7 @@ public static class ServiceCollectionExtensions // options.TenantResolvers.Add(new QueryStringTenantResolveContributor()); // options.TenantResolvers.Add(new RouteTenantResolveContributor()); options.TenantResolvers.Add(new HeaderTenantResolveContributor()); - // options.TenantResolvers.Add(new CookieTenantResolveContributor()); + options.TenantResolvers.Add(new CookieTenantResolveContributor()); }); return service; diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Roles/RoleAppService.cs b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Roles/RoleAppService.cs index cffa7cfa..4698e4d0 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Roles/RoleAppService.cs +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Roles/RoleAppService.cs @@ -4,16 +4,18 @@ namespace Lion.AbpPro.BasicManagement.Roles; public class RoleAppService : BasicManagementAppService, IRoleAppService { private readonly IIdentityRoleAppService _identityRoleAppService; - private readonly IIdentityRoleRepository _roleRepository; + private readonly ICurrentTenant _currentTenant; public RoleAppService( IIdentityRoleAppService identityRoleAppService, - IIdentityRoleRepository roleRepository) + IIdentityRoleRepository roleRepository, + ICurrentTenant currentTenant) { _identityRoleAppService = identityRoleAppService; _roleRepository = roleRepository; + _currentTenant = currentTenant; } /// @@ -60,6 +62,7 @@ public class RoleAppService : BasicManagementAppService, IRoleAppService [Authorize(IdentityPermissions.Roles.Create)] public virtual async Task CreateAsync(IdentityRoleCreateDto input) { + var s = _currentTenant; return await _identityRoleAppService.CreateAsync(input); } diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml index 0accf240..b8c612a3 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml @@ -1,3 +1,4 @@ + @page @model Lion.AbpPro.Pages.Login @@ -11,19 +12,43 @@ 后台服务登录 + -
-
-
-
+
+
+
+ @Html.AntiForgeryToken() + + @if (TempData["ErrorMessage"] != null) + { + + } 后台服务登录 + + @if (TempData["EnableTenant"] != null && (bool)TempData["EnableTenant"]) + { +
+
+ + +
+
+ }
- +
+ + +
- +
+ + +
@@ -34,141 +59,126 @@
- \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs index f2ef1002..38db169c 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs @@ -1,5 +1,7 @@ using Lion.AbpPro.BasicManagement.ConfigurationOptions; +using Lion.AbpPro.BasicManagement.Tenants; +using Lion.AbpPro.BasicManagement.Tenants.Dtos; using Lion.AbpPro.BasicManagement.Users; using Lion.AbpPro.BasicManagement.Users.Dtos; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -15,58 +17,94 @@ namespace Lion.AbpPro.Pages private readonly IHostEnvironment _hostEnvironment; private readonly JwtOptions _jwtOptions; private readonly IClock _clock; + private readonly AbpAspNetCoreMultiTenancyOptions _abpAspNetCoreMultiTenancyOptions; + private readonly IVoloTenantAppService _voloTenantAppService; + private readonly AbpProMultiTenancyOptions _abpProMultiTenancyOptions; public Login(IAccountAppService accountAppService, ILogger logger, IHostEnvironment hostEnvironment, IOptionsSnapshot jwtOptions, - IClock clock) + IClock clock, + IOptions abpAspNetCoreMultiTenancyOptions, + IVoloTenantAppService voloTenantAppService, + IOptions abpProMultiTenancyOptions) { _accountAppService = accountAppService; _logger = logger; _hostEnvironment = hostEnvironment; _clock = clock; + _voloTenantAppService = voloTenantAppService; + _abpProMultiTenancyOptions = abpProMultiTenancyOptions.Value; + _abpAspNetCoreMultiTenancyOptions = abpAspNetCoreMultiTenancyOptions.Value; _jwtOptions = jwtOptions.Value; + } public void OnGet() { + ViewData["ErrorMessage"] = null; + TempData["EnableTenant"] = _abpProMultiTenancyOptions.Enabled; } public async Task OnPost() { + TempData["EnableTenant"] = _abpProMultiTenancyOptions.Enabled; + string tenantName = Request.Form["tenantName"]; string userName = Request.Form["userName"]; string password = Request.Form["password"]; if (userName.IsNullOrWhiteSpace() || password.IsNullOrWhiteSpace()) { - Response.Redirect("/Login"); + // 添加错误提示信息 + TempData["ErrorMessage"] = "用户名和密码不能为空"; return; } try { + Guid? tenantId = null; + // 判断租户是否存在 + if (tenantName.IsNotNullOrWhiteSpace()) + { + var tenant = await _voloTenantAppService.FindTenantByNameAsync(new FindTenantByNameInput() { Name = tenantName }); + if (!tenant.Success) + { + TempData["ErrorMessage"] = $"租户[{tenantName}]不存在"; + return; + } + + tenantId = tenant.TenantId; + } + var options = new CookieOptions { Expires = _clock.Now.AddHours(_jwtOptions.ExpirationTime), SameSite = SameSiteMode.Unspecified, }; - - // 设置cookies domain - //options.Domain = "AbpPro.cn"; - - - var result = await _accountAppService.LoginAsync(new LoginInput() - { Name = userName, Password = password }); - Response.Cookies.Append(AbpProAspNetCoreConsts.DefaultCookieName, - result.Token, options); + var result = await _accountAppService.LoginAsync(new LoginInput() { Name = userName, Password = password }); + + // 清除现有的认证 cookies + Response.Cookies.Delete(AbpProAspNetCoreConsts.DefaultCookieName); + Response.Cookies.Delete(_abpAspNetCoreMultiTenancyOptions.TenantKey); + Response.Cookies.Append(AbpProAspNetCoreConsts.DefaultCookieName, result.Token, options); + if (tenantId.HasValue) + { + Response.Cookies.Append(_abpAspNetCoreMultiTenancyOptions.TenantKey, tenantId.ToString(), options); + } + + } + catch (BusinessException e) + { + _logger.LogError($"登录失败:{e.Message}"); + TempData["ErrorMessage"] = $"用户名或者密码错误"; + return; } catch (Exception e) { _logger.LogError($"登录失败:{e.Message}"); - Response.Redirect("/Login"); + TempData["ErrorMessage"] = $"登录失败:{e.Message}"; return; } - Response.Redirect("/monitor"); } } diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml index 5e4037c7..fe7e1631 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml @@ -1,204 +1,228 @@ + @page @using Lion.AbpPro @model Lion.AbpPro.Pages.Monitor - @{ Layout = null; } - - 后端服务 + + 后端服务监控 -
- -
-
-
- - +
+
+ + + -
- -
- - - - \ No newline at end of file + + .services-grid { + gap: clamp(15px, 3vw, 25px); + } + + .service-icon { + width: clamp(50px, 8vw, 60px); + height: clamp(50px, 8vw, 60px); + } + + .service-icon i { + font-size: clamp(20px, 4vw, 24px); + } + + + \ No newline at end of file diff --git a/vben28/.env.production b/vben28/.env.production index 57b52fb2..9a0e4bba 100644 --- a/vben28/.env.production +++ b/vben28/.env.production @@ -36,8 +36,8 @@ VITE_LEGACY = false # 接口地址 -VITE_API_URL= http://43.139.143.143:8080 +VITE_API_URL= http://139.155.114.244:44315 # WEBSOCKE 地址 -VITE_WEBSOCKE_URL= http://43.139.143.143:8080/signalr/notification +VITE_WEBSOCKE_URL= http://139.155.114.244:44315/signalr/notification