diff --git a/IRaCIS.Core.API/Startup.cs b/IRaCIS.Core.API/Startup.cs index 0fb15368a..97c96b374 100644 --- a/IRaCIS.Core.API/Startup.cs +++ b/IRaCIS.Core.API/Startup.cs @@ -76,7 +76,7 @@ namespace IRaCIS.Core.API //options.Filters.Add(); options.Filters.Add(); options.Filters.Add(); - //options.Filters.Add(); + options.Filters.Add(); if (_configuration.GetSection("BasicSystemConfig").GetValue("OpenLoginLimit")) { diff --git a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs index 321231f6e..a1a7e57dd 100644 --- a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs +++ b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs @@ -10,25 +10,35 @@ public static class SendEmailHelper public static async Task SendEmailAsync(MimeMessage messageToSend, EventHandler? messageSentSuccess = null) { - using (var smtp = new MailKit.Net.Smtp.SmtpClient()) + try { - if (messageSentSuccess != null) + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { - smtp.MessageSent += messageSentSuccess; + if (messageSentSuccess != null) + { + smtp.MessageSent += messageSentSuccess; + } + + + smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; + + await smtp.ConnectAsync("smtp.qq.com", 465, SecureSocketOptions.SslOnConnect); + + await smtp.AuthenticateAsync("zhou941003@qq.com", "sqfhlpfdvnexbcab"); + + await smtp.SendAsync(messageToSend); + + await smtp.DisconnectAsync(true); + } - - - smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; - - await smtp.ConnectAsync("smtp.qq.com", 465, SecureSocketOptions.SslOnConnect); - - await smtp.AuthenticateAsync("zhou941003@qq.com", "sqfhlpfdvnexbcab"); - - await smtp.SendAsync(messageToSend); - - await smtp.DisconnectAsync(true); - } + catch (Exception ex) + { + + throw new Exception("邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员") ; + } + + } public static async Task SendEmailAsync(SMTPEmailConfig sMTPEmailConfig, EventHandler? messageSentSuccess = null) diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 59aa9c28e..f90e0e6f6 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -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("该用户类型中已存在具有相同的电话的用户。"); } @@ -78,7 +78,7 @@ namespace IRaCIS.Application.Services throw new BusinessValidationFailedException("新密码与旧密码相同。"); } - + var dbUser = (await _userRepository.Where(t => t.Id == userId).FirstOrDefaultAsync()).IfNullThrowException(); if (oldPwd != null && dbUser.Password != oldPwd) @@ -124,6 +124,7 @@ namespace IRaCIS.Application.Services [HttpPut("{newEmail}/{verificationCode}")] + [UnitOfWork] public async Task SetNewEmail(string newEmail, string verificationCode) { @@ -215,7 +216,7 @@ namespace IRaCIS.Application.Services public async Task InitSetUserNameAndPwd(Guid userId, string newUserName, string newPWd) { - + await VerifyUserPwdAsync(userId, newPWd); @@ -232,7 +233,7 @@ namespace IRaCIS.Application.Services EmailToken = String.Empty - }, true) ; + }, true); return ResponseOutput.Ok(); } @@ -244,7 +245,7 @@ namespace IRaCIS.Application.Services /// /// [HttpGet("{userId:guid}")] - + [UnitOfWork] public async Task ResetPassword(Guid userId) { @@ -252,11 +253,19 @@ namespace IRaCIS.Application.Services if (_hostEnvironment.EnvironmentName != "Development") { - pwd = "Extimaging." + new Random().Next(100, 1000); + pwd = "Extimaging." + new Random().Next(100, 1000); } - await _mailVerificationService.AdminResetPwdSendEmailAsync(userId, pwd); + try + { + await _mailVerificationService.AdminResetPwdSendEmailAsync(userId, pwd); + } + catch (Exception ex) + { + throw new BusinessValidationFailedException("请检查邮箱地址或者联系维护人员, 邮件发送失败, 未能创建账户成功"); + } + await _userRepository.UpdatePartialNowNoQueryAsync(userId, u => new User() { @@ -464,10 +473,10 @@ namespace IRaCIS.Application.Services /// /// /// - [UnitOfWork] + [UnitOfWork] public async Task> AddUser(UserCommand userAddModel) { - + await VerifyUserNameAsync(null, userAddModel.UserName); @@ -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 }); } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index a489b3c6b..1c7d083a5 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -163,7 +163,7 @@ namespace IRaCIS.Core.Application.Service } else - { + { return ResponseOutput.NotOk("人员信息不支持编辑,请删除后重新添加。"); } @@ -199,6 +199,7 @@ namespace IRaCIS.Core.Application.Service [HttpPost] [Authorize(Policy = IRaCISPolicy.PM_APM)] [TypeFilter(typeof(TrialResourceFilter))] + [UnitOfWork] public async Task 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);