用户发送邮件
parent
2d66e63bf4
commit
c5810f7b0d
|
@ -109,12 +109,18 @@
|
|||
<Content Update="NLog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="wwwroot\EmailTemplate\AdminResetUser.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="wwwroot\EmailTemplate\TrialSiteSurveyReject.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="wwwroot\EmailTemplate\TrialUserExistJoin.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="wwwroot\EmailTemplate\AdminAddUser.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="wwwroot\EmailTemplate\UserOptCommon.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
|
||||
<div style='padding-left: 40px;background: #f6f6f6'>
|
||||
<div style='padding-top: 20px;'>
|
||||
<div style='line-height: 40px;font-size: 18px'>
|
||||
尊敬的 {0} ,您好:
|
||||
</div>
|
||||
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
|
||||
展影医疗为您添加了账户,账户信息如下:
|
||||
</div>
|
||||
<span style="color: #00D1B2"></span>
|
||||
<div style='border: 1px solid #eee;box-sizing:border-box;width: 50%;background: #fff;padding: 20px;line-height: 40px;font-size: 14px;border-radius: 5px;margin-left: 60px;margin-bottom: 30px;'>
|
||||
<div>
|
||||
用户名: {1}
|
||||
</div>
|
||||
<div>
|
||||
角色: {2}
|
||||
</div>
|
||||
<div>
|
||||
首次登陆前,请通过该链接修改您的账户信息:
|
||||
<a href='{3}' style='margin-left:30px;font-size:14px;text-decoration: none;display: inline-block;color:#00D1B2;border-radius: 5px;line-height: 40px;text-align: center;'>
|
||||
初始化账号信息
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div style='line-height: 24px;font-size: 14px;color:#333;margin-top: 20px;padding-bottom: 40px;'>
|
||||
<div>祝您顺利!/Best Regards</div>
|
||||
<div style="font-size: 14px;">上海展影医疗科技有限公司</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
|
||||
<div style='padding-left: 40px;background: #f6f6f6'>
|
||||
<div style='padding-top: 20px;'>
|
||||
<div style='line-height: 40px;font-size: 18px'>
|
||||
尊敬的 {0} ,您好:
|
||||
</div>
|
||||
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
|
||||
展影医疗将您的账户密码已重置,账户信息如下:
|
||||
</div>
|
||||
<span style="color: #00D1B2"></span>
|
||||
<div style='border: 1px solid #eee;box-sizing:border-box;width: 50%;background: #fff;padding: 20px;line-height: 40px;font-size: 14px;border-radius: 5px;margin-left: 60px;margin-bottom: 30px;'>
|
||||
<div>
|
||||
用户名: {1}
|
||||
</div>
|
||||
<div>
|
||||
角色: {2}
|
||||
</div>
|
||||
<div>
|
||||
密码: {3}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div style='line-height: 24px;font-size: 14px;color:#333;margin-top: 20px;padding-bottom: 40px;'>
|
||||
<div>祝您顺利!/Best Regards</div>
|
||||
<div style="font-size: 14px;">上海展影医疗科技有限公司</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -18,6 +18,10 @@ namespace IRaCIS.Application.Services
|
|||
Task SendMailEditEmail(Guid userId, string userName, string emailAddress, int verificationCode);
|
||||
|
||||
Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode);
|
||||
|
||||
Task AddUserSendEmail(Guid userId, string routeUrl);
|
||||
|
||||
Task AdminResetPwdSendEmail(Guid userId);
|
||||
}
|
||||
|
||||
public class MailVerificationService : IMailVerificationService
|
||||
|
@ -28,14 +32,20 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
private readonly IWebHostEnvironment _hostEnvironment;
|
||||
|
||||
private readonly IRepository<User> _userRepository;
|
||||
|
||||
public MailVerificationService(IRepository<VerificationCode> verificationCodeRepository, IRepository<SystemBasicData> systemBasicDatarepository , IWebHostEnvironment hostEnvironment)
|
||||
|
||||
public MailVerificationService(IRepository<VerificationCode> verificationCodeRepository,
|
||||
IRepository<SystemBasicData> systemBasicDatarepository,
|
||||
IWebHostEnvironment hostEnvironment, IRepository<User> userRepository)
|
||||
{
|
||||
_verificationCodeRepository = verificationCodeRepository;
|
||||
_systemBasicDatarepository = systemBasicDatarepository;
|
||||
|
||||
_hostEnvironment = hostEnvironment;
|
||||
|
||||
_userRepository = userRepository;
|
||||
|
||||
}
|
||||
|
||||
//重置邮箱
|
||||
|
@ -68,13 +78,13 @@ namespace IRaCIS.Application.Services
|
|||
builder.HtmlBody = string.Format(templateInfo,
|
||||
$" 尊敬的 {userName} , ",
|
||||
"您正在进行邮箱重置操作",
|
||||
verificationCode
|
||||
verificationCode
|
||||
);
|
||||
}
|
||||
|
||||
messageToSend.Body = builder.ToMessageBody();
|
||||
|
||||
|
||||
|
||||
|
||||
EventHandler<MessageSentEventArgs> sucessHandle = (sender, args) =>
|
||||
{
|
||||
|
@ -98,6 +108,9 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//不登录 通过邮箱重置密码
|
||||
public async Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode)
|
||||
{
|
||||
|
@ -216,11 +229,102 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//添加用户发送邮件
|
||||
public async Task AddUserSendEmail(Guid userId, string routeUrl)
|
||||
{
|
||||
var sysUserInfo = (await _userRepository.Where(t => t.Id == userId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
|
||||
var messageToSend = new MimeMessage();
|
||||
//发件地址
|
||||
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
|
||||
//收件地址
|
||||
messageToSend.To.Add(new MailboxAddress(sysUserInfo.FullName, sysUserInfo.EMail));
|
||||
//主题
|
||||
messageToSend.Subject = "[来自展影IRC] 关于创建账户的提醒";
|
||||
|
||||
|
||||
|
||||
var builder = new BodyBuilder();
|
||||
|
||||
var pathToFile = _hostEnvironment.WebRootPath
|
||||
+ Path.DirectorySeparatorChar.ToString()
|
||||
+ "EmailTemplate"
|
||||
+ Path.DirectorySeparatorChar.ToString()
|
||||
+ "AdminAddUser.html";
|
||||
|
||||
|
||||
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
|
||||
{
|
||||
var templateInfo = SourceReader.ReadToEnd();
|
||||
|
||||
|
||||
builder.HtmlBody = string.Format(templateInfo,
|
||||
sysUserInfo.FullName,
|
||||
sysUserInfo.UserName,
|
||||
sysUserInfo.UserTypeRole.UserTypeShortName,
|
||||
routeUrl
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
messageToSend.Body = builder.ToMessageBody();
|
||||
|
||||
|
||||
await SendEmailHelper.SendEmailAsync(messageToSend);
|
||||
}
|
||||
|
||||
//管理员重置密码发送邮件
|
||||
public async Task AdminResetPwdSendEmail(Guid userId)
|
||||
{
|
||||
var sysUserInfo = (await _userRepository.Where(t => t.Id == userId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
var messageToSend = new MimeMessage();
|
||||
//发件地址
|
||||
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
|
||||
//收件地址
|
||||
messageToSend.To.Add(new MailboxAddress(sysUserInfo.FullName, sysUserInfo.EMail));
|
||||
//主题
|
||||
messageToSend.Subject = "[来自展影IRC] 关于重置账户密码的提醒";
|
||||
|
||||
|
||||
|
||||
var builder = new BodyBuilder();
|
||||
|
||||
var pathToFile = _hostEnvironment.WebRootPath
|
||||
+ Path.DirectorySeparatorChar.ToString()
|
||||
+ "EmailTemplate"
|
||||
+ Path.DirectorySeparatorChar.ToString()
|
||||
+ "AdminResetUser.html";
|
||||
|
||||
|
||||
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
|
||||
{
|
||||
var templateInfo = SourceReader.ReadToEnd();
|
||||
|
||||
|
||||
builder.HtmlBody = string.Format(templateInfo,
|
||||
sysUserInfo.FullName,
|
||||
sysUserInfo.UserName,
|
||||
sysUserInfo.UserTypeRole.UserTypeShortName,
|
||||
StaticData.DefaultPassword
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
messageToSend.Body = builder.ToMessageBody();
|
||||
|
||||
|
||||
await SendEmailHelper.SendEmailAsync(messageToSend);
|
||||
}
|
||||
|
||||
|
||||
//废弃 添加用户发送邮件
|
||||
public async Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode)
|
||||
|
@ -285,7 +389,7 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -154,13 +154,14 @@ namespace IRaCIS.Application.Contracts
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
public string UserCode { get; set; } = string.Empty;
|
||||
|
||||
public int VerificationCode { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class UserCommand : UserInfo
|
||||
{
|
||||
{
|
||||
|
||||
public string RoutUrl { get; set; } = string.Empty;
|
||||
|
||||
//public string FirstName { get; set; }
|
||||
//public string LastName { get; set; }
|
||||
}
|
||||
|
|
|
@ -245,6 +245,9 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
public async Task<IResponseOutput> ResetPassword(Guid userId)
|
||||
{
|
||||
|
||||
await _mailVerificationService.AdminResetPwdSendEmail(userId);
|
||||
|
||||
await _userRepository.UpdatePartialNowNoQueryAsync(userId, u => new User()
|
||||
{
|
||||
Password = MD5Helper.Md5(StaticData.DefaultPassword),
|
||||
|
@ -470,8 +473,6 @@ namespace IRaCIS.Application.Services
|
|||
saveItem.OrganizationName = "Zhizhun";
|
||||
}
|
||||
|
||||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
saveItem.Password = MD5Helper.Md5("123456");
|
||||
|
||||
|
@ -479,7 +480,9 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
var success = await _userRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode, VerificationCode = verificationCode });
|
||||
await _mailVerificationService.AddUserSendEmail(saveItem.Id, userAddModel.RoutUrl);
|
||||
|
||||
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode });
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue