Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8
continuous-integration/drone/push Build is passing

This commit is contained in:
he
2024-07-31 10:40:44 +08:00
15 changed files with 191 additions and 66 deletions
@@ -0,0 +1,71 @@
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Application.BusinessFilter
{
public class EncreptApiResultFilter : IAsyncResultFilter
{
private readonly IOptionsMonitor<EncreptResponseOption> _encreptResponseMonitor;
public EncreptApiResultFilter(IOptionsMonitor<EncreptResponseOption> encreptResponseMonitor)
{
_encreptResponseMonitor = encreptResponseMonitor;
}
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
if(_encreptResponseMonitor.CurrentValue.IsEnable)
{
if (context.Result is ObjectResult objectResult)
{
var statusCode = objectResult.StatusCode ?? context.HttpContext.Response.StatusCode;
var objectValue = objectResult.Value;
if (objectValue is IResponseOutput)
{
var responseOutput = objectValue as IResponseOutput<object>;
var path = context.HttpContext?.Request.Path.Value?.ToLower();
if(!string.IsNullOrEmpty(path) && path.Length>5 && _encreptResponseMonitor.CurrentValue.ApiPathList.Contains(path.ToLower()))
{
if(responseOutput.IsSuccess)
{
responseOutput.Code = ApiResponseCodeEnum.ResultEncrepted;
responseOutput.Data = JsonConvert.SerializeObject(Convert.ToBase64String(Encoding.UTF8.GetBytes(responseOutput.Data.ToString())));
objectResult.Value = responseOutput;
}
}
}
}
}
await next.Invoke();
}
}
}
@@ -8,8 +8,9 @@ namespace IRaCIS.Application.Services.BusinessFilter
/// 统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
/// by zhouhang 2021.09.12 周末
/// </summary>
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
{
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
{
/// <summary>
/// 异步版本
/// </summary>
@@ -26,15 +27,6 @@ namespace IRaCIS.Application.Services.BusinessFilter
//是200 并且没有包装 那么包装结果
if (statusCode == 200 && !(objectResult.Value is IResponseOutput))
{
//if (objectResult.Value == null)
//{
// var apiResponse = ResponseOutput.DBNotExist();
// objectResult.Value = apiResponse;
// objectResult.DeclaredType = apiResponse.GetType();
//}
//else
//{
var type = objectResult.Value?.GetType();
@@ -64,8 +56,6 @@ namespace IRaCIS.Application.Services.BusinessFilter
objectResult.DeclaredType = apiResponse.GetType();
}
//}
}
//如果不是200 是IResponseOutput 不处理
@@ -0,0 +1,44 @@
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Application.Helper
{
public static class EmailMaskHelper
{
//显示位数:3分之2的位数,向上取整
//取哪几个个值:最后一位和前面几位
//其他:3个***。
//比如:hlj23@126.com
//为:hlj***3@126.com
//he@126.com
//为:h*** e@126.com
public static string MaskEmail(string email)
{
// 找到 "@" 符号的位置
int atIndex = email.IndexOf('@');
string visiblePartBefore = email.Substring(0, atIndex);
string afterAt = email.Substring(atIndex + 1);
int visibleLength = (int)Math.Ceiling((double)visiblePartBefore.Length * 2 / 3);
// 替换中间两位字符为星号
string hiddenPartBeforeAt = visiblePartBefore.Substring(0, visibleLength - 1) + "***" + visiblePartBefore.Last();
// 组合隐藏和可见部分
string hiddenEmail = hiddenPartBeforeAt + "@" + afterAt;
return hiddenEmail;
}
}
}
@@ -256,7 +256,7 @@ namespace IRaCIS.Application.Services
var htmlBodyStr = string.Format(ReplaceCompanyName(input.htmlBodyStr),
"",
"Sir/Madam",
//---您正在进行邮箱重置密码操作
_localizer["Mail_ResettingPassword"],
verificationCode
@@ -300,7 +300,7 @@ namespace IRaCIS.Application.Services
var htmlBodyStr = string.Format(ReplaceCompanyName(input.htmlBodyStr),
"Sir or Madam",
"Sir/Madam",
//---您正在参与展影医疗IRC项目
_localizer["Mail_IRCProject", companyName],
verificationCode
@@ -342,7 +342,7 @@ namespace IRaCIS.Application.Services
var htmlBodyStr = string.Format(ReplaceCompanyName(input.htmlBodyStr),
"Sir or Madam",
"Sir/Madam",
//---您正在参与展影医疗IRC项目中心调研工作
_localizer["Mail_CenterResearchReminder", companyName],
verificationCode
@@ -18,6 +18,7 @@ using LoginReturnDTO = IRaCIS.Application.Contracts.LoginReturnDTO;
using IRaCIS.Core.Application.Auth;
using BeetleX.Redis.Commands;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Application.Helper;
namespace IRaCIS.Application.Services
{
@@ -676,7 +677,8 @@ namespace IRaCIS.Application.Services
await _mailVerificationService.SenMFAVerifyEmail(userId, userInfo.FullName, userInfo.EMail, verificationCode, (UserMFAType)mfaType);
return ResponseOutput.Ok();
var hiddenEmail = EmailMaskHelper.MaskEmail(userInfo.EMail);
return ResponseOutput.Ok(hiddenEmail);
}
/// <summary>
+5 -2
View File
@@ -261,9 +261,12 @@ namespace IRaCIS.Application.Services
[AllowAnonymous]
public async Task testwwwww([FromServices] IWebHostEnvironment env)
public async Task<string> testEmail([FromServices] IWebHostEnvironment env ,string email)
{
await Task.CompletedTask;
var hiddenEmail = EmailMaskHelper.MaskEmail(email);
return hiddenEmail;
}