修改用户校验
parent
536d80718e
commit
815ed6e31c
|
@ -37,7 +37,9 @@ namespace IRaCIS.Core.API
|
|||
.AddJsonFile($"appsettings.{environment}.json", false, true);
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
||||
Log.Logger.Warning($"当前环境:{environment}");
|
||||
|
||||
|
||||
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());
|
||||
|
||||
|
@ -50,7 +52,7 @@ namespace IRaCIS.Core.API
|
|||
//缓存项目的状态 匿名化数据
|
||||
await InitCache(host);
|
||||
|
||||
//Log.Logger.Error("»º´æÏîĿ״̬Íê±Ï");
|
||||
|
||||
|
||||
host.Run();
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
},
|
||||
"BasicSystemConfig": {
|
||||
|
||||
"OpenUserComplexPassword": true,
|
||||
"OpenUserComplexPassword": false,
|
||||
|
||||
"OpenSignDocumentBeforeWork": true,
|
||||
"OpenSignDocumentBeforeWork": false,
|
||||
|
||||
"OpenTrialRelationDelete": false
|
||||
"OpenTrialRelationDelete": true
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
"BasicSystemConfig": {
|
||||
|
||||
"OpenUserComplexPassword": false,
|
||||
"OpenUserComplexPassword": true,
|
||||
|
||||
"OpenSignDocumentBeforeWork": true
|
||||
}
|
||||
|
|
|
@ -41,26 +41,26 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
|
||||
|
||||
private async Task VerifyUserNameAsync(Guid userId, string userName)
|
||||
private async Task VerifyUserNameAsync(Guid? userId, string userName)
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == userName && t.Id != userId))
|
||||
if (await _userRepository.WhereIf(userId!=null,t=>t.Id!=userId).AnyAsync(t => t.UserName == userName ))
|
||||
{
|
||||
throw new BusinessValidationFailedException("用户名已经存在。");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task VerifyUserPhoneAsync(Guid userId, Guid userTypeId, string phone)
|
||||
private async Task VerifyUserPhoneAsync(Guid? userId, Guid userTypeId, string phone)
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => (t.Phone == phone && t.UserTypeId == userTypeId && t.Id != userId)))
|
||||
if (await _userRepository.WhereIf(userId != null, t => t.Id != userId).AnyAsync(t => (t.Phone == phone && t.UserTypeId == userTypeId )))
|
||||
{
|
||||
throw new BusinessValidationFailedException("该用户类型中已存在具有相同的电话的用户。");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task VerifyUserEmailAsync(Guid userId, Guid userTypeId, string email)
|
||||
private async Task VerifyUserEmailAsync(Guid? userId, Guid userTypeId, string email)
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => (t.EMail == email && t.UserTypeId == userTypeId && t.Id != userId)))
|
||||
if (await _userRepository.WhereIf(userId != null, t => t.Id != userId).AnyAsync(t => (t.EMail == email && t.UserTypeId == userTypeId)))
|
||||
{
|
||||
throw new BusinessValidationFailedException("该用户类型中已存在具有相同邮箱的用户。");
|
||||
}
|
||||
|
@ -78,8 +78,13 @@ namespace IRaCIS.Application.Services
|
|||
throw new BusinessValidationFailedException("新密码与旧密码相同。");
|
||||
}
|
||||
|
||||
|
||||
var dbUser = (await _userRepository.FirstOrDefaultAsync(t => t.Id == userId)).IfNullThrowException();
|
||||
|
||||
if (oldPwd != null && dbUser.Password != oldPwd)
|
||||
{
|
||||
throw new BusinessValidationFailedException("旧密码验证失败。");
|
||||
}
|
||||
|
||||
if (dbUser.Password == newPwd)
|
||||
{
|
||||
|
@ -87,10 +92,7 @@ namespace IRaCIS.Application.Services
|
|||
}
|
||||
|
||||
|
||||
if (dbUser.Password != oldPwd)
|
||||
{
|
||||
throw new BusinessValidationFailedException("旧密码验证失败。");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//正则 至少8个字符,至少1个大写字母,1个小写字母,1个数字和1个特殊字符:
|
||||
|
@ -441,7 +443,7 @@ namespace IRaCIS.Application.Services
|
|||
/// 根据用户Id获取用户详细信息[New]
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns></returns>xiuga
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<UserDetailDTO> GetUser(Guid id)
|
||||
{
|
||||
|
@ -457,10 +459,13 @@ namespace IRaCIS.Application.Services
|
|||
[UnitOfWork]
|
||||
public async Task<IResponseOutput<UserAddedReturnDTO>> AddUser(UserCommand userAddModel)
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == userAddModel.UserName || (t.EMail == userAddModel.EMail && t.UserTypeId == userAddModel.UserTypeId)))
|
||||
{
|
||||
return ResponseOutput.NotOk(" 该用户类型中已存在具有相同用户名或者邮箱的用户。", new UserAddedReturnDTO());
|
||||
}
|
||||
|
||||
|
||||
await VerifyUserNameAsync(null, userAddModel.UserName);
|
||||
|
||||
await VerifyUserEmailAsync(null, userAddModel.UserTypeId, userAddModel.EMail);
|
||||
|
||||
await VerifyUserPhoneAsync(null, userAddModel.UserTypeId, userAddModel.Phone);
|
||||
|
||||
|
||||
var saveItem = _mapper.Map<User>(userAddModel);
|
||||
|
@ -500,6 +505,7 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
await VerifyUserEmailAsync(model.Id, model.UserTypeId, model.EMail);
|
||||
|
||||
await VerifyUserPhoneAsync(model.Id, model.UserTypeId, model.Phone);
|
||||
|
||||
var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == model.Id);
|
||||
|
||||
|
|
Loading…
Reference in New Issue