邮箱正则配置到配置文件
This commit is contained in:
@@ -10,9 +10,41 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MimeKit;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service
|
||||
{
|
||||
|
||||
public static class SafeMailHelper
|
||||
{
|
||||
public static async Task Run(Func<Task> func, [CallerMemberName] string caller = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
await func();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Logger.Error($"【邮件失败 - {caller}】: {ex.Message}");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T?> Run<T>(Func<Task<T>> func, [CallerMemberName] string caller = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
return await func();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Logger.Error($"【邮件失败 - {caller}】: {ex.Message}");
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IMailVerificationService
|
||||
{
|
||||
|
||||
@@ -68,6 +100,8 @@ namespace IRaCIS.Core.Application.Service
|
||||
|
||||
if (configInfo == null)
|
||||
{
|
||||
Log.Logger.Error($"系统未找到当前场景:{scenario}邮件配置信息");
|
||||
|
||||
throw new BusinessValidationFailedException("系统未找到当前场景邮件配置信息,请联系运维人员核查");
|
||||
}
|
||||
|
||||
@@ -81,6 +115,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Logger.Error($"邮件模板内容有误,填充内容出现问题,需要核查{scenario}场景邮件配置信息");
|
||||
|
||||
throw new BusinessValidationFailedException("邮件模板内容有误,填充内容出现问题,请联系运维人员核查");
|
||||
}
|
||||
@@ -103,6 +138,8 @@ namespace IRaCIS.Core.Application.Service
|
||||
|
||||
if (configInfo == null)
|
||||
{
|
||||
Log.Logger.Error($"系统未找到当前场景:{scenario}邮件配置信息");
|
||||
|
||||
throw new BusinessValidationFailedException("系统未找到当前场景邮件配置信息,请联系运维人员核查");
|
||||
}
|
||||
|
||||
@@ -292,7 +329,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login"));
|
||||
|
||||
var redirectUrl = $"{domain}/api/User/UserRedirect?url={System.Web.HttpUtility.UrlEncode(routeUrl)}";
|
||||
|
||||
|
||||
|
||||
var companyName = _userInfo.IsEn_Us ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN;
|
||||
|
||||
|
||||
@@ -70,8 +70,9 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> SendEmialVerifyCode(SendEmialVerifyCodeInDto userInfo)
|
||||
{
|
||||
var emailRegexStr = _systemEmailConfig.EmailRegexStr;
|
||||
//检查手机或者邮箱是否有效
|
||||
if (!Regex.IsMatch(userInfo.Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||
if (!Regex.IsMatch(userInfo.Email, emailRegexStr))
|
||||
{
|
||||
//---请输入正确的邮箱地址。
|
||||
throw new BusinessValidationFailedException(_localizer["TrialSiteSurvey_InvalidEmail"]);
|
||||
@@ -271,8 +272,10 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo)
|
||||
{
|
||||
var emailRegexStr = _systemEmailConfig.EmailRegexStr;
|
||||
|
||||
//检查手机或者邮箱是否有效
|
||||
if (!Regex.IsMatch(userInfo.Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||
if (!Regex.IsMatch(userInfo.Email, emailRegexStr))
|
||||
{
|
||||
//---请输入正确的邮箱地址。
|
||||
throw new BusinessValidationFailedException(_localizer["TrialSiteSurvey_InvalidEmail"]);
|
||||
|
||||
@@ -486,7 +486,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
Log.Logger.Error($"【邮件失败 - ConfirmReviewer接口】: {ex.Message}");
|
||||
intoGroupItem.EnrollStatus = EnrollStatus.ConfirmIntoGroupFailed;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user