From e75e86ac0776116e780bf9b20b31f09f85435665 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 25 Mar 2023 20:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=B6=E6=A0=A1=E9=AA=8CVI?= =?UTF-8?q?P=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4=E5=92=8C=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/CustomAuthenticationProvider.java | 16 ++++++++++++---- .../com/xkrs/utilsnew/VipTimeRangeUtils.java | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) 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()); }