diff --git a/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java b/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java index 0371c7a..bd49739 100644 --- a/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java +++ b/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java @@ -1,10 +1,11 @@ package com.xkrs.common.account; -import com.xkrs.service.SysAuthorityService; import com.xkrs.model.entity.SysAuthorityEntity; import com.xkrs.model.entity.SysUserEntity; +import com.xkrs.service.SysAuthorityService; import com.xkrs.service.SysRoleService; import com.xkrs.service.SysUserService; +import com.xkrs.utilsnew.VipTimeRangeUtils; import com.xkrs.utilsold.DateTimeUtil; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.BadCredentialsException; @@ -70,12 +71,19 @@ public class CustomAuthenticationProvider implements AuthenticationProvider { // 检查用户是否存在 if (userEntity == null) { - throw new BadCredentialsException("账号不存在或错误,请您确认注册"); + throw new DisabledException("您的账号不存在,请您前往注册。"); } - // 检查用户是否激活 if (userEntity.getActiveFlag() != 0) { - throw new DisabledException("该账号还未激活,请联系管理员"); + throw new DisabledException("您的账号未激活,详情请联系客服人员。"); + } + // 检查用户是否在VIP时间范围内 + boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(userEntity.getVipTimeRangeJson()); + // 检查用户是否在试用期范围内 + boolean inTryTimeRange = VipTimeRangeUtils.checkIfInTryTimeRange(userEntity.getAddTime(), userEntity.getDayNum()); + //既不在VIP时间范围内 也不在试用期范围内 + if ((!inVipTimeRange) && (!inTryTimeRange)) { + throw new DisabledException("您的账号已到期,详情请联系客服人员。"); } // 认证逻辑 diff --git a/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java b/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java index 9904f2a..03877cf 100644 --- a/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java +++ b/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java @@ -18,6 +18,22 @@ public class VipTimeRangeUtils { private VipTimeRangeUtils() { } + public static boolean checkIfInTryTimeRange(String addTime, Long dayNum) { + return checkIfInTryTimeRange(addTime, dayNum, LocalDateTime.now()); + } + + /** + * 校验传入的时间是否在指定的试用期过期时间之前 + */ + public static boolean checkIfInTryTimeRange(String addTime, Long dayNum, LocalDateTime targetLocalDateTime) { + if (TextUtils.isEmpty(addTime) || dayNum == null || targetLocalDateTime == null) { + return false; + } + LocalDateTime addLocalDateTime = LocalDateTime.parse(addTime, DateTimeUtils.DATE_TIME_FORMATTER_1); + LocalDateTime tryLocalDateTime = addLocalDateTime.plusDays(dayNum); + return targetLocalDateTime.isBefore(tryLocalDateTime); + } + public static boolean checkIfInVipTimeRange(String vipTimeRangeJson) { return checkIfInVipTimeRange(vipTimeRangeJson, LocalDateTime.now()); }