工作单元 +发送邮件提示修改

Test.EIImageViewer
hang 2022-11-23 13:55:04 +08:00
parent 3bbba03113
commit 5805393d76
4 changed files with 53 additions and 28 deletions

View File

@ -76,7 +76,7 @@ namespace IRaCIS.Core.API
//options.Filters.Add<LogActionFilter>();
options.Filters.Add<ModelActionFilter>();
options.Filters.Add<ProjectExceptionFilter>();
//options.Filters.Add<UnitOfWorkFilter>();
options.Filters.Add<UnitOfWorkFilter>();
if (_configuration.GetSection("BasicSystemConfig").GetValue<bool>("OpenLoginLimit"))
{

View File

@ -9,6 +9,8 @@ public static class SendEmailHelper
{
public static async Task SendEmailAsync(MimeMessage messageToSend, EventHandler<MessageSentEventArgs>? messageSentSuccess = null)
{
try
{
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
{
@ -30,6 +32,14 @@ public static class SendEmailHelper
}
}
catch (Exception ex)
{
throw new Exception("邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员") ;
}
}
public static async Task SendEmailAsync(SMTPEmailConfig sMTPEmailConfig, EventHandler<MessageSentEventArgs>? messageSentSuccess = null)
{

View File

@ -43,7 +43,7 @@ namespace IRaCIS.Application.Services
private async Task VerifyUserNameAsync(Guid? userId, string userName)
{
if (await _userRepository.WhereIf(userId!=null,t=>t.Id!=userId).AnyAsync(t => t.UserName == userName ))
if (await _userRepository.WhereIf(userId != null, t => t.Id != userId).AnyAsync(t => t.UserName == userName))
{
throw new BusinessValidationFailedException("用户名已经存在。");
}
@ -51,7 +51,7 @@ namespace IRaCIS.Application.Services
private async Task VerifyUserPhoneAsync(Guid? userId, Guid userTypeId, string phone)
{
if (await _userRepository.WhereIf(userId != null, t => t.Id != userId).AnyAsync(t => (t.Phone == phone && t.UserTypeId == userTypeId )))
if (await _userRepository.WhereIf(userId != null, t => t.Id != userId).AnyAsync(t => (t.Phone == phone && t.UserTypeId == userTypeId)))
{
throw new BusinessValidationFailedException("该用户类型中已存在具有相同的电话的用户。");
}
@ -124,6 +124,7 @@ namespace IRaCIS.Application.Services
[HttpPut("{newEmail}/{verificationCode}")]
[UnitOfWork]
public async Task<IResponseOutput> SetNewEmail(string newEmail, string verificationCode)
{
@ -232,7 +233,7 @@ namespace IRaCIS.Application.Services
EmailToken = String.Empty
}, true) ;
}, true);
return ResponseOutput.Ok();
}
@ -244,7 +245,7 @@ namespace IRaCIS.Application.Services
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet("{userId:guid}")]
[UnitOfWork]
public async Task<IResponseOutput> ResetPassword(Guid userId)
{
@ -256,7 +257,15 @@ namespace IRaCIS.Application.Services
}
try
{
await _mailVerificationService.AdminResetPwdSendEmailAsync(userId, pwd);
}
catch (Exception ex)
{
throw new BusinessValidationFailedException("请检查邮箱地址或者联系维护人员, 邮件发送失败, 未能创建账户成功");
}
await _userRepository.UpdatePartialNowNoQueryAsync(userId, u => new User()
{
@ -480,7 +489,7 @@ namespace IRaCIS.Application.Services
saveItem.Code = await _userRepository.Select(t => t.Code).DefaultIfEmpty().MaxAsync() + 1;
saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)) ;
saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User));
if (saveItem.IsZhiZhun)
{
@ -494,8 +503,12 @@ namespace IRaCIS.Application.Services
var success = await _userRepository.SaveChangesAsync();
await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl);
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode });
}

View File

@ -199,6 +199,7 @@ namespace IRaCIS.Core.Application.Service
[HttpPost]
[Authorize(Policy = IRaCISPolicy.PM_APM)]
[TypeFilter(typeof(TrialResourceFilter))]
[UnitOfWork]
public async Task<IResponseOutput> SendExternalUserJoinEmail(TrialExternalUserSendEmail sendEmail)
{
var trialId = sendEmail.TrialId;
@ -207,6 +208,7 @@ namespace IRaCIS.Core.Application.Service
{
var userId = userInfo.SystemUserId;
await _mailVerificationService.ExternalUserJoinEmail(trialId, userId, sendEmail.BaseUrl, sendEmail.RouteUrl);