1. 修复 isEmpty 的 bug。

2. 重构校验器。
This commit is contained in:
2022-12-09 17:37:10 +08:00
parent 70f4a9fb45
commit 08f8da3516
8 changed files with 374 additions and 154 deletions

View File

@@ -15,13 +15,13 @@ import xyz.zhouxy.plusone.validator.DtoValidator;
@DtoValidator(LoginByOtpCommand.class)
public class LoginByOtpCommandValidator extends BaseValidator<LoginByOtpCommand> {
public LoginByOtpCommandValidator() {
ruleFor(loginCommand -> {
withRule(loginCommand -> {
String principal = loginCommand.getPrincipal();
return StringUtils.hasText(principal)
&&
RegexUtil.matchesOr(principal, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE);
}, "输入邮箱地址或手机号");
ruleFor(loginCommand -> {
withRule(loginCommand -> {
String otp = loginCommand.getOtp();
return StringUtils.hasText(otp) && Pattern.matches(RegexConsts.CAPTCHA, otp);
}, "验证码不符合要求");

View File

@@ -15,13 +15,13 @@ import xyz.zhouxy.plusone.validator.DtoValidator;
@DtoValidator(LoginByPasswordCommand.class)
public class LoginByPasswordCommandValidator extends BaseValidator<LoginByPasswordCommand> {
public LoginByPasswordCommandValidator() {
ruleFor(loginCommand -> {
withRule(loginCommand -> {
String principal = loginCommand.getPrincipal();
return StringUtils.hasText(principal)
&&
RegexUtil.matchesOr(principal, RegexConsts.USERNAME, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE, principal);
}, "输入用户名、邮箱地址或手机号");
ruleFor(loginCommand -> {
withRule(loginCommand -> {
String password = loginCommand.getPassword();
return StringUtils.hasText(password)
&&