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

This commit is contained in:
2022-11-23 13:55:04 +08:00
parent 3bbba03113
commit 5805393d76
4 changed files with 53 additions and 28 deletions
@@ -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 });
}