diff --git a/IRaCIS.Core.API/IRaCIS.Core.API.csproj b/IRaCIS.Core.API/IRaCIS.Core.API.csproj
index 998069f61..e6053ff27 100644
--- a/IRaCIS.Core.API/IRaCIS.Core.API.csproj
+++ b/IRaCIS.Core.API/IRaCIS.Core.API.csproj
@@ -109,12 +109,18 @@
Always
+
+ Always
+
Always
Always
+
+ Always
+
Always
diff --git a/IRaCIS.Core.API/wwwroot/EmailTemplate/AdminAddUser.html b/IRaCIS.Core.API/wwwroot/EmailTemplate/AdminAddUser.html
new file mode 100644
index 000000000..9191707f8
--- /dev/null
+++ b/IRaCIS.Core.API/wwwroot/EmailTemplate/AdminAddUser.html
@@ -0,0 +1,40 @@
+
+
+
+
+ Title
+
+
+
+
+
+ 尊敬的 {0} ,您好:
+
+
+ 展影医疗为您添加了账户,账户信息如下:
+
+
+
+
+ 用户名: {1}
+
+
+ 角色: {2}
+
+
+
+
+
+
+
祝您顺利!/Best Regards
+
上海展影医疗科技有限公司
+
+
+
+
+
diff --git a/IRaCIS.Core.API/wwwroot/EmailTemplate/AdminResetUser.html b/IRaCIS.Core.API/wwwroot/EmailTemplate/AdminResetUser.html
new file mode 100644
index 000000000..e81216184
--- /dev/null
+++ b/IRaCIS.Core.API/wwwroot/EmailTemplate/AdminResetUser.html
@@ -0,0 +1,37 @@
+
+
+
+
+ Title
+
+
+
+
+
+ 尊敬的 {0} ,您好:
+
+
+ 展影医疗将您的账户密码已重置,账户信息如下:
+
+
+
+
+ 用户名: {1}
+
+
+ 角色: {2}
+
+
+ 密码: {3}
+
+
+
+
+
+
祝您顺利!/Best Regards
+
上海展影医疗科技有限公司
+
+
+
+
+
diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs
index 4551636fe..0da1c671b 100644
--- a/IRaCIS.Core.Application/Service/Common/MailService.cs
+++ b/IRaCIS.Core.Application/Service/Common/MailService.cs
@@ -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 _userRepository;
- public MailVerificationService(IRepository verificationCodeRepository, IRepository systemBasicDatarepository , IWebHostEnvironment hostEnvironment)
+
+ public MailVerificationService(IRepository verificationCodeRepository,
+ IRepository systemBasicDatarepository,
+ IWebHostEnvironment hostEnvironment, IRepository 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 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);
-
+
}
diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs
index afd13f610..91cdbaf8e 100644
--- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs
+++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs
@@ -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; }
}
diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs
index 80c7fb3e0..5aac478e8 100644
--- a/IRaCIS.Core.Application/Service/Management/UserService.cs
+++ b/IRaCIS.Core.Application/Service/Management/UserService.cs
@@ -245,6 +245,9 @@ namespace IRaCIS.Application.Services
public async Task 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 });
}