From 645534fcf7d75e49c0bfb9b0753805f11828e220 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Fri, 6 Jan 2023 16:33:36 +0800 Subject: [PATCH] =?UTF-8?q?api=E6=8E=88=E6=9D=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Myshipping.Application.xml | 185 ++++++++++++++++++ .../Service/DataSync/DataSyncService.cs | 8 + Myshipping.Core/Filter/ApiUserFilter.cs | 25 ++- 3 files changed, 209 insertions(+), 9 deletions(-) diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index 9cd8a635..cf3b89a9 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -9963,6 +9963,191 @@ 租户ID + + + 数据同步服务 + + + + + 订舱客户同步 + + + + + 主键 + + + + + 代码 + + + + + 简称 + + + + + 全称 + + + + + 负责人 + + + + + 电话 + + + + + 邮箱 + + + + + QQ + + + + + 网址 + + + + + 省份 + + + + + 城市 + + + + + 地址 + + + + + 英文全名 + + + + + 英文地址 + + + + + 属性字符串 + + + + + 发票抬头 + + + + + 纳税人识别号 + + + + + 发票地址电话 + + + + + 人民币开户行 + + + + + 人民币账号 + + + + + 美元开户行 + + + + + 美元账号 + + + + + 备注 + + + + + 联系人 + + + + + 订舱客户联系人同步 + + + + + 主键 + + + + + 客户Id + + + + + 角色ID + + + + + 角色名称 + + + + + 名称 + + + + + 电话 + + + + + 邮箱 + + + + + QQ + + + + + 排序号 + + + + + 备注 + + 主键 diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 9b95b45c..d343a194 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -73,5 +73,13 @@ namespace Myshipping.Application #region 下载数据 #endregion + + #region 其他 + [HttpGet("/DataSync/Test"), ApiUser] + public async Task Test() + { + return $"当前用户:{UserManager.UserId} {UserManager.Name} ,当前租户:{UserManager.TENANT_ID} {UserManager.TENANT_NAME},管理员类型:{(UserManager.IsSuperAdmin ? "超级管理员" : (UserManager.IsTenantAdmin ? "租户管理员" : "普通用户"))}"; + } + #endregion } } diff --git a/Myshipping.Core/Filter/ApiUserFilter.cs b/Myshipping.Core/Filter/ApiUserFilter.cs index be767fe3..210c8f6e 100644 --- a/Myshipping.Core/Filter/ApiUserFilter.cs +++ b/Myshipping.Core/Filter/ApiUserFilter.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; +using Myshipping.Core.Entity; using System; using System.Collections.Generic; using System.Linq; @@ -20,19 +21,25 @@ namespace Myshipping.Core { if (metadata.GetType() == typeof(ApiUserAttribute)) { - if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY) - && context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET)) + //if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY) + //&& context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET)) { var httpContext = App.GetService().HttpContext; + var repTenant = App.GetService>(); + var repUser = App.GetService>(); + + var tenant = repTenant.AsQueryable().Filter(null, true).First(x => x.Id == 142307070918780L); + var user = repUser.AsQueryable().Filter(null, true).First(x => x.Id == 142307070910551L); + ClaimsIdentity identity = new ClaimsIdentity("AuthenticationTypes.Federation"); - identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: "111")); - identity.AddClaim(new Claim(type: ClaimConst.TENANT_ID, value: "10")); - identity.AddClaim(new Claim(type: ClaimConst.CLAINM_ACCOUNT, value: "admin")); - identity.AddClaim(new Claim(type: ClaimConst.CLAINM_NAME, value: "管理员")); - identity.AddClaim(new Claim(type: ClaimConst.CLAINM_SUPERADMIN, value: AdminType.Admin.ToString())); - identity.AddClaim(new Claim(type: ClaimConst.CLAINM_TENANT_TYPE, value: TenantTypeEnum.SYSTEM.ToString())); - identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: "测试")); + identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: user.Id.ToString())); + identity.AddClaim(new Claim(type: ClaimConst.CLAINM_ACCOUNT, value: user.Account)); + identity.AddClaim(new Claim(type: ClaimConst.CLAINM_NAME, value: user.Name)); + identity.AddClaim(new Claim(type: ClaimConst.CLAINM_SUPERADMIN, value: ((int)user.AdminType).ToString())); + identity.AddClaim(new Claim(type: ClaimConst.CLAINM_TENANT_TYPE, value: tenant.TenantType.ToString())); + identity.AddClaim(new Claim(type: ClaimConst.TENANT_ID, value: tenant.Id.ToString())); + identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: tenant.Name)); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity); httpContext.User = claimsPrincipal; }