工作单元 +发送邮件提示修改
							parent
							
								
									3bbba03113
								
							
						
					
					
						commit
						5805393d76
					
				| 
						 | 
				
			
			@ -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"))
 | 
			
		||||
                {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,25 +10,35 @@ public static class SendEmailHelper
 | 
			
		|||
 | 
			
		||||
    public static async Task SendEmailAsync(MimeMessage messageToSend, EventHandler<MessageSentEventArgs>? 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<MessageSentEventArgs>? messageSentSuccess = null)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<IResponseOutput> SetNewEmail(string newEmail, string verificationCode)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -215,7 +216,7 @@ namespace IRaCIS.Application.Services
 | 
			
		|||
        public async Task<IResponseOutput> 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
 | 
			
		|||
        /// <param name="userId"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        [HttpGet("{userId:guid}")]
 | 
			
		||||
 | 
			
		||||
        [UnitOfWork]
 | 
			
		||||
        public async Task<IResponseOutput> 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
 | 
			
		|||
        /// </summary>
 | 
			
		||||
        /// <param name="userAddModel"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
       [UnitOfWork]
 | 
			
		||||
        [UnitOfWork]
 | 
			
		||||
        public async Task<IResponseOutput<UserAddedReturnDTO>> 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 });
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue