修改邮件发送
parent
a1e06f6536
commit
d3af4696c2
|
@ -1,6 +1,5 @@
|
|||
using Autofac;
|
||||
using Autofac.Extras.DynamicProxy;
|
||||
using IRaCIS.Core.API.Utility.AOP;
|
||||
using IRaCIS.Core.Application;
|
||||
using IRaCIS.Core.Application.AOP;
|
||||
using IRaCIS.Core.Application.BackGroundJob;
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
using Castle.DynamicProxy;
|
||||
using IRaCIS.Application.Services;
|
||||
using IRaCIS.Application.Contracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using IRaCIS.Core.Infrastructure.Extention;
|
||||
|
||||
namespace IRaCIS.Core.API.Utility.AOP
|
||||
{
|
||||
/// <summary>
|
||||
///服务动态生成api AOP 此时会失效
|
||||
/// </summary>
|
||||
public class UserAddAOP : IInterceptor
|
||||
{
|
||||
private readonly IMailVerificationService _mailVerificationService;
|
||||
private readonly ILogger<UserAddAOP> _logger;
|
||||
|
||||
public UserAddAOP(IMailVerificationService mailVerificationService, ILogger<UserAddAOP> logger)
|
||||
{
|
||||
_mailVerificationService = mailVerificationService;
|
||||
_logger = logger;
|
||||
}
|
||||
public void Intercept(IInvocation invocation)
|
||||
{
|
||||
|
||||
var userInfo = (invocation.Arguments[0] as UserCommand).IfNullThrowConvertException();
|
||||
|
||||
|
||||
//处理拦截的方法
|
||||
invocation.Proceed();
|
||||
|
||||
//在此 发送邮件
|
||||
dynamic result = invocation.ReturnValue;
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
var userId = result.Data.Id;
|
||||
var verificationCode = result.Data.VerificationCode;
|
||||
|
||||
|
||||
_logger.LogInformation($"Sent to {userInfo.UserName} email {userInfo.EMail} init password {verificationCode}");
|
||||
|
||||
_mailVerificationService.SendMail(userId, userInfo.UserName, userInfo.EMail, verificationCode).GetAwaiter().GetResult();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Threading.Tasks;
|
||||
using IRaCIS.Core.Infrastructure.Extention;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace IRaCIS.Application.Services.BusinessFilter
|
||||
|
|
|
@ -919,7 +919,7 @@
|
|||
TrialSiteSurveyService
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Contracts.TrialSiteSurveyService.SendVerifyCode(IRaCIS.Core.Application.Contracts.SiteSurveySendVerifyCode,IRaCIS.Application.Services.IMailVerificationService)">
|
||||
<member name="M:IRaCIS.Core.Application.Contracts.TrialSiteSurveyService.SendVerifyCode(IRaCIS.Core.Application.Contracts.SiteSurveySendVerifyCode)">
|
||||
<summary>
|
||||
发送验证码
|
||||
</summary>
|
||||
|
@ -1786,11 +1786,6 @@
|
|||
构造函数注入
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.API.Utility.AOP.UserAddAOP">
|
||||
<summary>
|
||||
服务动态生成api AOP 此时会失效
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Application.Services.BusinessFilter.UnifiedApiResultFilter">
|
||||
<summary>
|
||||
统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
||||
|
|
|
@ -11,7 +11,6 @@ namespace IRaCIS.Application.Services
|
|||
{
|
||||
public interface IMailVerificationService
|
||||
{
|
||||
Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode);
|
||||
|
||||
Task AnolymousSendEmail(string researchProgramNo, string emailAddress, int verificationCode);
|
||||
|
||||
|
@ -458,72 +457,6 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
|
||||
|
||||
//废弃 添加用户发送邮件
|
||||
public async Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode)
|
||||
{
|
||||
|
||||
|
||||
var messageToSend = new MimeMessage();
|
||||
//发件地址
|
||||
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
|
||||
//收件地址
|
||||
messageToSend.To.Add(new MailboxAddress(userName, emailAddress));
|
||||
//主题
|
||||
messageToSend.Subject = "[来自展影IRC] 关于重置邮箱的提醒";
|
||||
|
||||
|
||||
|
||||
var builder = new BodyBuilder();
|
||||
|
||||
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
|
||||
<div style='padding-left: 40px;background: #f6f6f6'>
|
||||
<div style='padding-top: 20px;padding-bottom:40px'>
|
||||
<div style='line-height: 40px;font-size: 18px'>
|
||||
您好:
|
||||
</div>
|
||||
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
|
||||
感谢您使用展影云平台。
|
||||
</div>
|
||||
<div>
|
||||
您正在进行邮箱重置操作,验证码是: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件。
|
||||
</div>
|
||||
<div>
|
||||
此邮件属系统自动发出,无需回复。
|
||||
</div>
|
||||
<div>
|
||||
祝您顺利!/Best Regards。
|
||||
</div>
|
||||
<div>
|
||||
上海展影医疗科技有限公司
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>";
|
||||
|
||||
|
||||
messageToSend.Body = builder.ToMessageBody();
|
||||
|
||||
|
||||
EventHandler<MessageSentEventArgs> sucessHandle = (sender, args) =>
|
||||
{
|
||||
// args.Response
|
||||
var code = verificationCode.ToString();
|
||||
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
|
||||
{
|
||||
CodeType = 0,
|
||||
HasSend = true,
|
||||
Code = code,
|
||||
UserId = userId,
|
||||
ExpirationTime = DateTime.Now.AddMinutes(3)
|
||||
}).Result;
|
||||
_ = _verificationCodeRepository.SaveChangesAsync().Result;
|
||||
};
|
||||
|
||||
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
Task<LoginReturnDTO> GetSiteSurveyInfo(Guid trialSiteSurveyId, Guid trialId);
|
||||
Task<PageOutput<TrialSiteSurveyView>> GetTrialSiteSurveyList(TrialSiteSurveyQueryDTO surveyQueryDTO);
|
||||
Task<TrialSurveyInitInfo> GetTrialSurveyInitInfo(Guid trialId);
|
||||
Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo, [FromServices] IMailVerificationService _mailVerificationService);
|
||||
Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo);
|
||||
//Task<IResponseOutput> TrialSurveyLock(Guid trialSiteSurveyId, bool isLock);
|
||||
//IResponseOutput TrialSurveySubmmit(Guid trialId, Guid trialSiteSurveyId);
|
||||
Task<IResponseOutput> VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService);
|
||||
|
|
|
@ -30,9 +30,12 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
|
||||
private readonly IRepository<TrialUser> _trialUserRepository;
|
||||
private readonly ITokenService _tokenService;
|
||||
private readonly IMailVerificationService _mailVerificationService;
|
||||
|
||||
public TrialSiteSurveyService(IRepository<TrialSiteSurvey> trialSiteSurveyRepository, IRepository<TrialUser> trialUserRepository, IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository,
|
||||
IRepository<User> userRepository, IRepository<TrialSite> trialSiteRepository, ITokenService tokenService)
|
||||
IRepository<User> userRepository, IRepository<TrialSite> trialSiteRepository,
|
||||
ITokenService tokenService,
|
||||
IMailVerificationService mailVerificationService)
|
||||
{
|
||||
_trialSiteSurveyRepository = trialSiteSurveyRepository;
|
||||
_trialSiteUserSurveyRepository = trialSiteUserSurveyRepository;
|
||||
|
@ -40,6 +43,7 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
_trialUserRepository = trialUserRepository;
|
||||
_trialSiteRepository = trialSiteRepository;
|
||||
_tokenService = tokenService;
|
||||
_mailVerificationService = mailVerificationService;
|
||||
}
|
||||
|
||||
private object lockObj { get; set; } = new object();
|
||||
|
@ -51,7 +55,7 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
/// <param name="_mailVerificationService"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo, [FromServices] IMailVerificationService _mailVerificationService)
|
||||
public async Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo)
|
||||
{
|
||||
var verificationType = VerifyType.Email;
|
||||
//检查手机或者邮箱是否有效
|
||||
|
@ -745,7 +749,7 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
}
|
||||
|
||||
|
||||
public async Task<IResponseOutput> SendSiteSurveyUserJoinEmail(TrialSiteUserSurveyJoinCommand joinCommand, [FromServices] IMailVerificationService _mailVerificationService)
|
||||
public async Task<IResponseOutput> SendSiteSurveyUserJoinEmail(TrialSiteUserSurveyJoinCommand joinCommand)
|
||||
{
|
||||
var trialSiteSurvey = (await _trialSiteSurveyRepository.Where(t => t.Id == joinCommand.TrialSiteSurveyId).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
|
|
Loading…
Reference in New Issue