mirror of https://github.com/halo-dev/halo
refactor: optimize user creation (#6480)
#### What type of PR is this? /kind improvement /area core /milestone 2.19.x #### What this PR does / why we need it: 优化用户创建 #### Does this PR introduce a user-facing change? ```release-note None ```pull/6482/head
parent
7774eb1a3a
commit
30d482f0f8
|
@ -444,13 +444,9 @@ public class UserEndpoint implements CustomEndpoint {
|
|||
})
|
||||
.flatMap(userRequest -> {
|
||||
User newUser = CreateUserRequest.from(userRequest);
|
||||
return userService.createUser(newUser, userRequest.roles())
|
||||
.then(Mono.defer(() -> userService.updateWithRawPassword(userRequest.name(),
|
||||
userRequest.password()))
|
||||
.retryWhen(Retry.backoff(5, Duration.ofMillis(100))
|
||||
.filter(OptimisticLockingFailureException.class::isInstance)
|
||||
)
|
||||
);
|
||||
var encryptedPwd = userService.encryptPassword(userRequest.password());
|
||||
newUser.getSpec().setPassword(encryptedPwd);
|
||||
return userService.createUser(newUser, userRequest.roles());
|
||||
})
|
||||
.flatMap(user -> ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
|
|
|
@ -27,4 +27,6 @@ public interface UserService {
|
|||
Mono<Boolean> confirmPassword(String username, String rawPassword);
|
||||
|
||||
Flux<User> listByEmail(String email);
|
||||
|
||||
String encryptPassword(String rawPassword);
|
||||
}
|
||||
|
|
|
@ -213,6 +213,11 @@ public class UserServiceImpl implements UserService {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encryptPassword(String rawPassword) {
|
||||
return passwordEncoder.encode(rawPassword);
|
||||
}
|
||||
|
||||
void publishPasswordChangedEvent(String username) {
|
||||
eventPublisher.publishEvent(new PasswordChangedEvent(this, username));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue