Compare commits
No commits in common. "c73c722b87b6a4a7899bebb0d2099475f4a27bcf" and "46a72e63c0bc82b9df6d1a3f1870cc0240999ee9" have entirely different histories.
c73c722b87
...
46a72e63c0
|
@ -0,0 +1,18 @@
|
|||
package xyz.zhouxy.plusone.exception.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
@Configuration
|
||||
public class PlusoneExceptionHandlerConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ExceptionInfoHolder exceptionInfoHolder() {
|
||||
return new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
/**
|
||||
* AllExceptionHandlerConfig
|
||||
*/
|
||||
|
@ -12,7 +14,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
public class AllExceptionHandlerConfig {
|
||||
|
||||
@Bean
|
||||
AllExceptionHandler getAllExceptionHandler() {
|
||||
return new AllExceptionHandler(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
return new AllExceptionHandler(exceptionInfoHolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ import xyz.zhouxy.plusone.util.RestfulResult;
|
|||
@Slf4j
|
||||
public class DefaultExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public DefaultExceptionHandler() {
|
||||
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN);
|
||||
set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true);
|
||||
set(MethodArgumentNotValidException.class,
|
||||
4040401,
|
||||
e -> e.getAllErrors()
|
||||
e -> ((MethodArgumentNotValidException) e).getAllErrors()
|
||||
.stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||
.toList()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>plusone-basic</artifactId>
|
||||
|
@ -39,12 +39,12 @@
|
|||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-validator</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-exception-handler</artifactId>
|
||||
<version>0.0.6-SNAPSHOT</version>
|
||||
<version>0.0.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package xyz.zhouxy.plusone.exception.handler;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
public class ExceptionInfoHolderFactory {
|
||||
|
||||
private ExceptionInfoHolderFactory() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static ExceptionInfoHolder newDefaultExceptionInfoHolder() {
|
||||
return new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package xyz.zhouxy.plusone.sql;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.ibatis.jdbc.AbstractSQL;
|
||||
|
||||
/**
|
||||
* 扩展 MyBatis 中的 SQL 语句构造器
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public class SQL extends AbstractSQL<SQL> {
|
||||
|
||||
public SQL SET_IF(boolean condition, String sets) {
|
||||
return condition ? SET(sets) : getSelf();
|
||||
}
|
||||
|
||||
public SQL SET_IF_NOT_NULL(Object param, String sets) {
|
||||
return Objects.nonNull(param) ? SET(sets) : getSelf();
|
||||
}
|
||||
|
||||
public SQL WHERE_IF(boolean condition, String sqlCondition) {
|
||||
return condition ? WHERE(sqlCondition) : getSelf();
|
||||
}
|
||||
|
||||
public SQL WHERE_IF_NOT_NULL(Object param, String sqlCondition) {
|
||||
return Objects.nonNull(param) ? WHERE(sqlCondition) : getSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQL getSelf() {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -2,14 +2,14 @@ package xyz.zhouxy.plusone.validator;
|
|||
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class InvalidInputExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
protected InvalidInputExceptionHandler() {
|
||||
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
super(new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE));
|
||||
set(InvalidInputException.class, InvalidInputException.ERROR_CODE, "无效的用户输入");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
import xyz.zhouxy.plusone.validator.validator2.BaseValidator2;
|
||||
|
||||
class BaseValidator2Test {
|
||||
|
||||
|
@ -27,16 +27,15 @@ class LoginCommand {
|
|||
private boolean rememberMe;
|
||||
}
|
||||
|
||||
class LoginCommandValidator extends BaseValidator<LoginCommand> {
|
||||
class LoginCommandValidator extends BaseValidator2<LoginCommand> {
|
||||
|
||||
public static final LoginCommandValidator INSTANCE = new LoginCommandValidator();
|
||||
|
||||
private LoginCommandValidator() {
|
||||
ruleForString(LoginCommand::getAccount)
|
||||
ruleFor(LoginCommand::getAccount)
|
||||
.notNull("邮箱地址不能为空")
|
||||
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE },
|
||||
value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
||||
ruleForString(LoginCommand::getPwd)
|
||||
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE }, value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
||||
ruleFor(LoginCommand::getPwd)
|
||||
.notNull("密码不能为空")
|
||||
.notEmpty("密码不能为空")
|
||||
.matches(RegexConsts.PASSWORD, "密码格式错误");
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
|
||||
<description>参考 DDD 落地的脚手架</description>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.7.6</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package xyz.zhouxy.plusone.system.application.exception.handler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class AccountLoginExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
protected AccountLoginExceptionHandler() {
|
||||
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
}
|
||||
|
||||
@ExceptionHandler({ AccountLoginException.class })
|
||||
public ResponseEntity<RestfulResult> handleException(@Nonnull Exception e) {
|
||||
return buildExceptionResponse(e);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ import cn.dev33.satoken.exception.SaTokenException;
|
|||
import cn.dev33.satoken.exception.SameTokenInvalidException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
|
||||
/**
|
||||
|
@ -27,8 +26,8 @@ import xyz.zhouxy.plusone.util.RestfulResult;
|
|||
@Slf4j
|
||||
public class SaTokenExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public SaTokenExceptionHandler() {
|
||||
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
public SaTokenExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
set(NotPermissionException.class, 4030103, "会话未能通过权限认证", HttpStatus.FORBIDDEN);
|
||||
set(NotRoleException.class, 4030103, "会话未能通过角色认证", HttpStatus.FORBIDDEN);
|
||||
set(DisableServiceException.class, 4030202, "账号指定服务已被封禁", HttpStatus.FORBIDDEN);
|
||||
|
@ -37,7 +36,7 @@ public class SaTokenExceptionHandler extends BaseExceptionHandler {
|
|||
set(NotSafeException.class, 4020300, "会话未能通过二级认证", HttpStatus.UNAUTHORIZED);
|
||||
set(NotLoginException.class,
|
||||
4020400,
|
||||
e -> switch (e.getType()) {
|
||||
e -> switch (((NotLoginException) e).getType()) {
|
||||
case NotLoginException.NOT_TOKEN -> "未提供 Token";
|
||||
case NotLoginException.INVALID_TOKEN -> "Token 无效";
|
||||
case NotLoginException.TOKEN_TIMEOUT -> "Token 已过期";
|
||||
|
|
|
@ -2,12 +2,12 @@ package xyz.zhouxy.plusone.system.application.query;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.zhouxy.plusone.sql.SQL;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.DictQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.DictOverview;
|
||||
|
||||
|
@ -26,21 +26,14 @@ public class DictQueries {
|
|||
}
|
||||
|
||||
public List<DictOverview> queryDictOverviewList(DictQueryParams queryParams) {
|
||||
String sql = new SQL() {
|
||||
{
|
||||
SELECT("id", "dict_type", "dict_label",
|
||||
"created_by", "create_time", "updated_by", "update_time", "count");
|
||||
FROM("view_sys_dict_overview");
|
||||
if (queryParams.getDictType() != null) {
|
||||
WHERE("dict_type LIKE '%:dictType%'");
|
||||
}
|
||||
if (queryParams.getDictLabel() != null) {
|
||||
WHERE("dict_label LIKE '%:dictLabel%'");
|
||||
}
|
||||
}
|
||||
}.toString();
|
||||
String sql = new SQL()
|
||||
.SELECT("id", "dict_type", "dict_label",
|
||||
"created_by", "create_time", "updated_by", "update_time", "count")
|
||||
.FROM("view_sys_dict_overview")
|
||||
.WHERE_IF(queryParams.getDictType() != null, "dict_type LIKE '%:dictType%'")
|
||||
.WHERE_IF(queryParams.getDictLabel() != null, "dict_label LIKE '%:dictLabel%'")
|
||||
.toString();
|
||||
return this.jdbcTemplate
|
||||
.query(sql, new BeanPropertySqlParameterSource(queryParams),
|
||||
new BeanPropertyRowMapper<>(DictOverview.class));
|
||||
.query(sql, new BeanPropertySqlParameterSource(queryParams), new BeanPropertyRowMapper<>(DictOverview.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
|||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
import xyz.zhouxy.plusone.sql.SQL;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.RoleOverview;
|
||||
|
||||
|
@ -35,47 +35,30 @@ public class RoleQueries {
|
|||
* @return 查询结果
|
||||
*/
|
||||
public List<RoleOverview> query(RoleQueryParams params) {
|
||||
var sql = new SQL() {
|
||||
{
|
||||
SELECT("a.id AS id", "a.name AS name", "a.identifier AS identifier", "a.status AS status");
|
||||
FROM("sys_role AS a", "(" +
|
||||
new SQL() {
|
||||
{
|
||||
SELECT("id");
|
||||
FROM("sys_role");
|
||||
if (null != params.getId()) {
|
||||
WHERE("id = :id");
|
||||
}
|
||||
if (null != params.getName()) {
|
||||
WHERE("name = :name");
|
||||
}
|
||||
if (null != params.getIdentifier()) {
|
||||
WHERE("identifier = :identifier");
|
||||
}
|
||||
if (null != params.getStatus()) {
|
||||
WHERE("status = :status");
|
||||
}
|
||||
if (null != params.getCreateTimeStart()) {
|
||||
WHERE("create_time >= :createTimeStart");
|
||||
}
|
||||
if (null != params.getCreateTimeEnd()) {
|
||||
WHERE("create_time < :createTimeEnd");
|
||||
}
|
||||
if (null != params.getUpdateTimeStart()) {
|
||||
WHERE("update_time >= :updateTimeStart");
|
||||
}
|
||||
if (null != params.getUpdateTimeEnd()) {
|
||||
WHERE("update_time < :updateTimeEnd");
|
||||
}
|
||||
LIMIT(params.getSize());
|
||||
OFFSET(params.getOffset());
|
||||
}
|
||||
}.toString() + ") AS b");
|
||||
WHERE("a.id = b.id");
|
||||
}
|
||||
}.toString();
|
||||
String b = new SQL()
|
||||
.SELECT("id")
|
||||
.FROM("sys_role")
|
||||
.WHERE_IF_NOT_NULL(params.getId(), "id = :id")
|
||||
.WHERE_IF_NOT_NULL(params.getName(), "name = :name")
|
||||
.WHERE_IF_NOT_NULL(params.getIdentifier(), "identifier = :identifier")
|
||||
.WHERE_IF_NOT_NULL(params.getStatus(), "status = :status")
|
||||
.WHERE_IF_NOT_NULL(params.getCreateTimeStart(), "create_time >= :createTimeStart")
|
||||
.WHERE_IF_NOT_NULL(params.getCreateTimeEnd(), "create_time < :createTimeEnd")
|
||||
.WHERE_IF_NOT_NULL(params.getUpdateTimeStart(), "update_time >= :updateTimeStart")
|
||||
.WHERE_IF_NOT_NULL(params.getUpdateTimeEnd(), "update_time < :updateTimeEnd")
|
||||
.LIMIT(params.getSize())
|
||||
.OFFSET(params.getOffset())
|
||||
.toString();
|
||||
var sql = """
|
||||
SELECT a.id AS id, a.name AS name, a.identifier AS identifier, a.status AS status
|
||||
FROM sys_role AS a, (
|
||||
""" + b + """
|
||||
) AS b
|
||||
WHERE a.id = b.id
|
||||
""";
|
||||
return this.jdbcTemplate
|
||||
.query(sql, new BeanPropertySqlParameterSource(params),
|
||||
new BeanPropertyRowMapper<>(RoleOverview.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
|
|||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Password;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
import xyz.zhouxy.plusone.validator.InvalidInputException;
|
||||
|
||||
|
@ -79,10 +78,10 @@ public class RegisterAccountService {
|
|||
Username.of(username),
|
||||
email,
|
||||
mobilePhone,
|
||||
Password.newPassword(command.getPassword(), command.getReenteredPassword()),
|
||||
Password.newPassword(command.getPassword(), command.getPasswordConfirmation()),
|
||||
AccountStatus.AVAILABLE,
|
||||
Set.of(DEFAULT_ROLE_ID),
|
||||
AccountInfo.of(command.getNickname(), null, Sex.UNSET));
|
||||
AccountInfo.of(command.getNickname(), command.getAvatar(), command.getSex()));
|
||||
accountRepository.save(accountToSave);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,12 @@ package xyz.zhouxy.plusone.system.application.service.command;
|
|||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
|
||||
import lombok.Data;
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.domain.ICommand;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
|
||||
/**
|
||||
* 注册账号命令
|
||||
|
@ -29,8 +32,14 @@ public class RegisterAccountCommand implements ICommand {
|
|||
@NotBlank
|
||||
@Pattern(regexp = RegexConsts.PASSWORD)
|
||||
String password;
|
||||
String reenteredPassword;
|
||||
String passwordConfirmation;
|
||||
|
||||
@Pattern(regexp = RegexConsts.NICKNAME)
|
||||
String nickname;
|
||||
|
||||
@NotBlank
|
||||
@URL
|
||||
String avatar;
|
||||
|
||||
Sex sex;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package xyz.zhouxy.plusone.system.application.service.command.validator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByOtpCommand;
|
||||
import xyz.zhouxy.plusone.util.RegexUtil;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
import xyz.zhouxy.plusone.validator.DtoValidator;
|
||||
|
||||
|
@ -13,13 +15,15 @@ import xyz.zhouxy.plusone.validator.DtoValidator;
|
|||
@DtoValidator(LoginByOtpCommand.class)
|
||||
public class LoginByOtpCommandValidator extends BaseValidator<LoginByOtpCommand> {
|
||||
public LoginByOtpCommandValidator() {
|
||||
ruleForString(LoginByOtpCommand::getPrincipal)
|
||||
.notNull("输入邮箱地址或手机号")
|
||||
.notEmpty("输入邮箱地址或手机号")
|
||||
.matchesOr(List.of(RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE), "输入用户名、邮箱地址或手机号");
|
||||
ruleForString(LoginByOtpCommand::getOtp)
|
||||
.notNull("验证码不能为空")
|
||||
.notEmpty("验证码不能为空")
|
||||
.matches(RegexConsts.CAPTCHA, "验证码格式不正确");
|
||||
withRule(loginCommand -> {
|
||||
String principal = loginCommand.getPrincipal();
|
||||
return StringUtils.hasText(principal)
|
||||
&&
|
||||
RegexUtil.matchesOr(principal, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE);
|
||||
}, "输入邮箱地址或手机号");
|
||||
withRule(loginCommand -> {
|
||||
String otp = loginCommand.getOtp();
|
||||
return StringUtils.hasText(otp) && Pattern.matches(RegexConsts.CAPTCHA, otp);
|
||||
}, "验证码不符合要求");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package xyz.zhouxy.plusone.system.application.service.command.validator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.LoginByPasswordCommand;
|
||||
import xyz.zhouxy.plusone.util.RegexUtil;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
import xyz.zhouxy.plusone.validator.DtoValidator;
|
||||
|
||||
|
@ -11,14 +15,17 @@ import xyz.zhouxy.plusone.validator.DtoValidator;
|
|||
@DtoValidator(LoginByPasswordCommand.class)
|
||||
public class LoginByPasswordCommandValidator extends BaseValidator<LoginByPasswordCommand> {
|
||||
public LoginByPasswordCommandValidator() {
|
||||
ruleForString(LoginByPasswordCommand::getPrincipal)
|
||||
.notNull("输入用户名、邮箱地址或手机号")
|
||||
.notEmpty("输入用户名、邮箱地址或手机号")
|
||||
.matchesOr(List.of(RegexConsts.USERNAME, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE),
|
||||
"输入用户名、邮箱地址或手机号");
|
||||
ruleForString(LoginByPasswordCommand::getPassword)
|
||||
.notNull("密码不能为空")
|
||||
.notEmpty("密码不能为空")
|
||||
.matches(RegexConsts.PASSWORD, "密码格式不正确");
|
||||
withRule(loginCommand -> {
|
||||
String principal = loginCommand.getPrincipal();
|
||||
return StringUtils.hasText(principal)
|
||||
&&
|
||||
RegexUtil.matchesOr(principal, RegexConsts.USERNAME, RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE, principal);
|
||||
}, "输入用户名、邮箱地址或手机号");
|
||||
withRule(loginCommand -> {
|
||||
String password = loginCommand.getPassword();
|
||||
return StringUtils.hasText(password)
|
||||
&&
|
||||
Pattern.matches(RegexConsts.PASSWORD, password);
|
||||
}, "密码格式不正确");
|
||||
}
|
||||
}
|
||||
|
|
47
pom.xml
47
pom.xml
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -26,23 +25,21 @@
|
|||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
|
||||
<spring-boot.version>2.7.8</spring-boot.version>
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
<hutool.version>5.8.11</hutool.version>
|
||||
<mybatis-starter.version>3.0.1</mybatis-starter.version>
|
||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||
<spring-boot.version>2.7.6</spring-boot.version>
|
||||
<sa-token.version>1.32.0</sa-token.version>
|
||||
<hutool.version>5.8.9</hutool.version>
|
||||
<mybatis-starter.version>2.2.2</mybatis-starter.version>
|
||||
<mybatis-plus.version>3.5.2</mybatis-plus.version>
|
||||
<commons-io.version>2.11.0</commons-io.version>
|
||||
<mica.version>2.7.5</mica.version>
|
||||
<mapstruct.version>1.5.3.Final</mapstruct.version>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
<guava.version>30.1-jre</guava.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<commons-collections4.version>4.4</commons-collections4.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<commons-pool2.version>2.11.1</commons-pool2.version>
|
||||
<tencentcloud-sdk.version>3.1.681</tencentcloud-sdk.version>
|
||||
<fastdfs.version>1.29-SNAPSHOT</fastdfs.version>
|
||||
<okio.version>3.0.0</okio.version>
|
||||
<okhttp.version>4.10.0</okhttp.version>
|
||||
<okio.version>1.12.0</okio.version>
|
||||
<tencentcloud-sdk.version>3.1.622</tencentcloud-sdk.version>
|
||||
|
||||
<plusone-basic.version>1.0.0-SNAPSHOT</plusone-basic.version>
|
||||
<plusone-system.version>1.0.0-SNAPSHOT</plusone-system.version>
|
||||
|
@ -129,6 +126,12 @@
|
|||
<version>${mica.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okio</groupId>
|
||||
<artifactId>okio</artifactId>
|
||||
<version>${okio.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
@ -166,24 +169,6 @@
|
|||
<artifactId>commons-pool2</artifactId>
|
||||
<version>${commons-pool2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.csource</groupId>
|
||||
<artifactId>fastdfs-client-java</artifactId>
|
||||
<version>${fastdfs.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okio</groupId>
|
||||
<artifactId>okio</artifactId>
|
||||
<version>${okio.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue