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 -> {
|
.flatMap(userRequest -> {
|
||||||
User newUser = CreateUserRequest.from(userRequest);
|
User newUser = CreateUserRequest.from(userRequest);
|
||||||
return userService.createUser(newUser, userRequest.roles())
|
var encryptedPwd = userService.encryptPassword(userRequest.password());
|
||||||
.then(Mono.defer(() -> userService.updateWithRawPassword(userRequest.name(),
|
newUser.getSpec().setPassword(encryptedPwd);
|
||||||
userRequest.password()))
|
return userService.createUser(newUser, userRequest.roles());
|
||||||
.retryWhen(Retry.backoff(5, Duration.ofMillis(100))
|
|
||||||
.filter(OptimisticLockingFailureException.class::isInstance)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.flatMap(user -> ServerResponse.ok()
|
.flatMap(user -> ServerResponse.ok()
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
|
|
@ -27,4 +27,6 @@ public interface UserService {
|
||||||
Mono<Boolean> confirmPassword(String username, String rawPassword);
|
Mono<Boolean> confirmPassword(String username, String rawPassword);
|
||||||
|
|
||||||
Flux<User> listByEmail(String email);
|
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) {
|
void publishPasswordChangedEvent(String username) {
|
||||||
eventPublisher.publishEvent(new PasswordChangedEvent(this, username));
|
eventPublisher.publishEvent(new PasswordChangedEvent(this, username));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue