mirror of
https://github.com/halo-dev/halo.git
synced 2024-10-23 09:26:03 +08:00
Bind sign up data instead of building by hand (#6895)
#### What type of PR is this? /kind improvement /area core /milestone 2.20.x #### What this PR does / why we need it: This PR refactors sign up data binding using internal `bind` method in `ServerRequest` instead of binding my hand. It's more convenient and simpler. #### Does this PR introduce a user-facing change? ```release-note None ```
This commit is contained in:
parent
697a5e5a4c
commit
3570353ce2
@ -13,10 +13,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import run.halo.app.infra.ValidationUtils;
|
||||
|
||||
/**
|
||||
@ -52,35 +49,6 @@ public class SignUpData {
|
||||
@NotBlank
|
||||
private String confirmPassword;
|
||||
|
||||
public static SignUpData of(MultiValueMap<String, String> formData) {
|
||||
var form = new SignUpData();
|
||||
Optional.ofNullable(formData.getFirst("username"))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(form::setUsername);
|
||||
|
||||
Optional.ofNullable(formData.getFirst("displayName"))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(form::setDisplayName);
|
||||
|
||||
Optional.ofNullable(formData.getFirst("email"))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(form::setEmail);
|
||||
|
||||
Optional.ofNullable(formData.getFirst("password"))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(form::setPassword);
|
||||
|
||||
Optional.ofNullable(formData.getFirst("emailCode"))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(form::setEmailCode);
|
||||
|
||||
Optional.ofNullable(formData.getFirst("confirmPassword"))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(form::setConfirmPassword);
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = {SignUpDataConstraintValidator.class})
|
||||
|
@ -79,8 +79,7 @@ class PreAuthSignUpEndpoint {
|
||||
.POST(
|
||||
"",
|
||||
contentType(APPLICATION_FORM_URLENCODED),
|
||||
request -> request.formData()
|
||||
.map(SignUpData::of)
|
||||
request -> request.bind(SignUpData.class)
|
||||
.flatMap(signUpData -> {
|
||||
// sign up
|
||||
var bindingResult = validate(signUpData, validator, request.exchange());
|
||||
|
Loading…
Reference in New Issue
Block a user