Browse Source

🚑 Bug修复

pull/11/head 4.4.0.14
王军 5 years ago
parent
commit
448258cbd3
  1. 18
      aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/Pages/Login.cshtml.cs
  2. 59
      aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs
  3. 3
      vben271/.env.development
  4. 7
      vben271/.env.production
  5. 2
      vben271/package.json
  6. 2
      vben271/src/hooks/web/useSignalR.ts
  7. 4
      vben271/src/views/admin/roles/PermissionAbpRole.vue

18
aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/Pages/Login.cshtml.cs

@ -16,7 +16,8 @@ namespace CompanyName.ProjectName.Pages
private readonly ILogger<Login> _logger; private readonly ILogger<Login> _logger;
private readonly IHostEnvironment _hostEnvironment; private readonly IHostEnvironment _hostEnvironment;
public Login(IAccountAppService accountAppService, ILogger<Login> logger, IHostEnvironment hostEnvironment) public Login(IAccountAppService accountAppService, ILogger<Login> logger,
IHostEnvironment hostEnvironment)
{ {
_accountAppService = accountAppService; _accountAppService = accountAppService;
_logger = logger; _logger = logger;
@ -26,7 +27,7 @@ namespace CompanyName.ProjectName.Pages
public void OnGet() public void OnGet()
{ {
} }
public async Task OnPost() public async Task OnPost()
{ {
string userName = Request.Form["userName"]; string userName = Request.Form["userName"];
@ -44,16 +45,15 @@ namespace CompanyName.ProjectName.Pages
SameSite = SameSiteMode.Unspecified, SameSite = SameSiteMode.Unspecified,
}; };
if (!_hostEnvironment.IsDevelopment())
{
// 设置cookies domain
options.Domain = "ProjectName.cn";
}
// 设置cookies domain
//options.Domain = "ProjectName.cn";
var result = await _accountAppService.LoginAsync(new LoginInput() var result = await _accountAppService.LoginAsync(new LoginInput()
{ Name = userName, Password = password }); { Name = userName, Password = password });
Response.Cookies.Append(ProjectNameHttpApiHostConsts.DefaultCookieName, result.Token,options); Response.Cookies.Append(ProjectNameHttpApiHostConsts.DefaultCookieName,
result.Token, options);
} }
catch (Exception e) catch (Exception e)
{ {

59
aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs

@ -21,6 +21,7 @@ using Swashbuckle.AspNetCore.SwaggerUI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CompanyName.ProjectName.CAP; using CompanyName.ProjectName.CAP;
@ -61,7 +62,6 @@ namespace CompanyName.ProjectName
)] )]
public class ProjectNameHttpApiHostModule : AbpModule public class ProjectNameHttpApiHostModule : AbpModule
{ {
public override void OnPostApplicationInitialization( public override void OnPostApplicationInitialization(
ApplicationInitializationContext context) ApplicationInitializationContext context)
{ {
@ -114,7 +114,7 @@ namespace CompanyName.ProjectName
opts.EnrichDiagnosticContext = SerilogToEsExtensions.EnrichFromRequest; opts.EnrichDiagnosticContext = SerilogToEsExtensions.EnrichFromRequest;
}); });
app.UseUnitOfWork(); app.UseUnitOfWork();
app.UseConfiguredEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); }); app.UseConfiguredEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); });
app.UseHangfireDashboard("/hangfire", new DashboardOptions() app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{ {
@ -187,31 +187,38 @@ namespace CompanyName.ProjectName
OnMessageReceived = currentContext => OnMessageReceived = currentContext =>
{ {
var path = currentContext.HttpContext.Request.Path; var path = currentContext.HttpContext.Request.Path;
if (!path.StartsWithSegments("/login")) if (path.StartsWithSegments("/login"))
{ {
var accessToken = return Task.CompletedTask;
currentContext.Request.Cookies[ }
ProjectNameHttpApiHostConsts.DefaultCookieName] ;
var accessToken =
if (!accessToken.IsNullOrWhiteSpace()) currentContext.Request.Query["access_token"].FirstOrDefault() ??
{ currentContext.Request.Cookies[
if (path.StartsWithSegments("/signalr")) ProjectNameHttpApiHostConsts.DefaultCookieName];
{
currentContext.Token = accessToken; if (!accessToken.IsNullOrWhiteSpace())
} {
return Task.CompletedTask;
currentContext.Request.Headers.Add("Authorization", }
$"Bearer {accessToken}");
if (path.StartsWithSegments("/signalr"))
// 如果请求来自hangfire 或者cap {
if (path.ToString().StartsWith("/hangfire") || currentContext.Token = accessToken;
path.ToString().StartsWith("/cap")) }
{
currentContext.HttpContext.Response.Headers.Remove( currentContext.Request.Headers.Add("Authorization",
"X-Frame-Options"); $"Bearer {accessToken}");
currentContext.Token = !string.IsNullOrEmpty(accessToken) ? accessToken : accessToken;
} // 如果请求来自hangfire 或者cap
} if (path.ToString().StartsWith("/hangfire") ||
path.ToString().StartsWith("/cap"))
{
currentContext.HttpContext.Response.Headers.Remove(
"X-Frame-Options");
currentContext.Token = !string.IsNullOrEmpty(accessToken)
? accessToken
: accessToken;
} }

3
vben271/.env.development

@ -30,4 +30,5 @@ VITE_AUTH_URL= http://localhost:44354
VITE_API_URL= http://localhost:44314/gateway VITE_API_URL= http://localhost:44314/gateway
VITE_WEBSOCKE_URL= http://localhost:44314 # WEBSOCKE 地址
VITE_WEBSOCKE_URL= http://localhost:44314/ws

7
vben271/.env.production

@ -36,8 +36,11 @@ VITE_LEGACY = false
# 认证授权服务器地址 # 认证授权服务器地址
VITE_AUTH_URL='http://120.24.194.14:8013' VITE_AUTH_URL= http://localhost:44354
# 接口地址 # 接口地址
VITE_API_URL= http://120.24.194.14:8011 VITE_API_URL= http://localhost:44314/gateway
# WEBSOCKE 地址
VITE_WEBSOCKE_URL= http://localhost:44314/ws

2
vben271/package.json

@ -118,7 +118,7 @@
"ts-jest": "^27.0.4", "ts-jest": "^27.0.4",
"ts-node": "^10.2.0", "ts-node": "^10.2.0",
"typescript": "4.3.5", "typescript": "4.3.5",
"vite": "2.5.9", "vite": "2.6.14",
"vite-plugin-compression": "^0.3.3", "vite-plugin-compression": "^0.3.3",
"vite-plugin-html": "^2.0.7", "vite-plugin-html": "^2.0.7",
"vite-plugin-imagemin": "^0.4.3", "vite-plugin-imagemin": "^0.4.3",

2
vben271/src/hooks/web/useSignalR.ts

@ -22,7 +22,7 @@ export function useSignalR() {
const userStore = useUserStoreWithOut(); const userStore = useUserStoreWithOut();
const token = userStore.getToken; const token = userStore.getToken;
const url = (import.meta.env.VITE_WEBSOCKE_URL as string) + '/ws/signalr/notification'; const url = (import.meta.env.VITE_WEBSOCKE_URL as string) + '/signalr/notification';
const connection = new signalR.HubConnectionBuilder() const connection = new signalR.HubConnectionBuilder()
.withUrl(url, { .withUrl(url, {
accessTokenFactory: () => token, accessTokenFactory: () => token,

4
vben271/src/views/admin/roles/PermissionAbpRole.vue

@ -92,7 +92,9 @@
request.providerName = 'R'; request.providerName = 'R';
request.providerKey = roleName; request.providerKey = roleName;
const { checked } = toRaw(getTree().getCheckedKeys()) as []; const { checked } = toRaw(getTree().getCheckedKeys()) as [];
if (checked == undefined) {
return;
}
const noSelectedPermissions = totalRolePermissionsRef.filter((e) => { const noSelectedPermissions = totalRolePermissionsRef.filter((e) => {
return !(checked.indexOf(e) > -1); return !(checked.indexOf(e) > -1);
}); });

Loading…
Cancel
Save