|
@@ -129,12 +129,7 @@ public class UserController : BaseController
|
|
|
public async Task Update([FromBody] UpdateUserDto dto)
|
|
|
{
|
|
|
var account = await _accountRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
- if (account is null)
|
|
|
- throw UserFriendlyException.SameMessage("账号不存在");
|
|
|
- if (_accountDomainService.IsLockedOut(account))
|
|
|
- throw UserFriendlyException.SameMessage("账号已被锁定");
|
|
|
- if(account.IsDeleted)
|
|
|
- throw UserFriendlyException.SameMessage("账号不存在");
|
|
|
+ CheckAccountStatus(account);
|
|
|
|
|
|
var user = await _userRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
if (user is null)
|
|
@@ -297,12 +292,7 @@ public class UserController : BaseController
|
|
|
public async Task ChangePassword([FromBody] ChangePasswordDto dto)
|
|
|
{
|
|
|
var account = await _accountRepository.GetAsync(_sessionContext.RequiredUserId, HttpContext.RequestAborted);
|
|
|
- if (account == null)
|
|
|
- throw UserFriendlyException.SameMessage("无效账号编号");
|
|
|
- if (_accountDomainService.IsLockedOut(account))
|
|
|
- throw UserFriendlyException.SameMessage("账号已被锁定");
|
|
|
- if (account.IsDeleted)
|
|
|
- throw UserFriendlyException.SameMessage("账号不存在");
|
|
|
+ CheckAccountStatus(account);
|
|
|
|
|
|
var result = await _accountDomainService.ResetPasswordAsync(account, dto.CurrentPassword, dto.NewPassword,
|
|
|
HttpContext.RequestAborted);
|
|
@@ -320,13 +310,8 @@ public class UserController : BaseController
|
|
|
public async Task InitialPassword(string userId)
|
|
|
{
|
|
|
var account = await _accountRepository.GetAsync(userId, HttpContext.RequestAborted);
|
|
|
- if (account == null)
|
|
|
- throw UserFriendlyException.SameMessage("无效账号编号");
|
|
|
- if (_accountDomainService.IsLockedOut(account))
|
|
|
- throw UserFriendlyException.SameMessage("账号已被锁定");
|
|
|
- if (account.IsDeleted)
|
|
|
- throw UserFriendlyException.SameMessage("账号不存在");
|
|
|
- await _accountDomainService.InitialPasswordAsync(account, HttpContext.RequestAborted);
|
|
|
+ CheckAccountStatus(account);
|
|
|
+ await _accountDomainService.InitialPasswordAsync(account, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -370,4 +355,15 @@ public class UserController : BaseController
|
|
|
GenderOptions = EnumExts.GetDescriptions<EGender>()
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void CheckAccountStatus(Account? account)
|
|
|
+ {
|
|
|
+ if (account == null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效账号编号");
|
|
|
+ if (_accountDomainService.IsLockedOut(account))
|
|
|
+ throw UserFriendlyException.SameMessage("账号已被锁定");
|
|
|
+ if (account.IsDeleted)
|
|
|
+ throw UserFriendlyException.SameMessage("账号不存在");
|
|
|
+ }
|
|
|
}
|