diff --git a/server/like-front/src/main/java/com/mdd/front/LikeFrontInterceptor.java b/server/like-front/src/main/java/com/mdd/front/LikeFrontInterceptor.java index e89c7b08..baf81850 100644 --- a/server/like-front/src/main/java/com/mdd/front/LikeFrontInterceptor.java +++ b/server/like-front/src/main/java/com/mdd/front/LikeFrontInterceptor.java @@ -9,6 +9,7 @@ import com.mdd.common.enums.HttpEnum; import com.mdd.common.mapper.user.UserMapper; import com.mdd.common.utils.RedisUtil; import com.mdd.common.utils.StringUtil; +import com.mdd.common.utils.YmlUtil; import com.mdd.front.config.FrontConfig; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; @@ -78,22 +79,24 @@ public class LikeFrontInterceptor implements HandlerInterceptor { .last("limit 1")); // 校验用户被删除 - if (user.getIsDelete() == 1) { + if (user.getIsDelete().equals(1)) { AjaxResult result = AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), HttpEnum.TOKEN_INVALID.getMsg()); response.getWriter().print(JSON.toJSONString(result)); return false; } // 校验用户被禁用 - if (user.getIsDisable() == 1) { + if (user.getIsDisable().equals(1)) { AjaxResult result = AjaxResult.failed(HttpEnum.LOGIN_DISABLE_ERROR.getCode(), HttpEnum.LOGIN_DISABLE_ERROR.getMsg()); response.getWriter().print(JSON.toJSONString(result)); return false; } - // 令牌剩余30分钟自动续签 - if (RedisUtil.ttl(token) < 1800) { - RedisUtil.expire(token, 7200L); + // 令牌自动续签 + int tokenRenewTime = Integer.parseInt(YmlUtil.get("like.token-renew-time")); + if (RedisUtil.ttl(token) < tokenRenewTime) { + long tokenValidTime = Long.parseLong(YmlUtil.get("like.token-valid-time")); + RedisUtil.expire(token, tokenValidTime); } // 写入本地线程 diff --git a/server/like-front/src/main/java/com/mdd/front/service/impl/LoginServiceImpl.java b/server/like-front/src/main/java/com/mdd/front/service/impl/LoginServiceImpl.java index 8d82586d..fcbe4a53 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/impl/LoginServiceImpl.java +++ b/server/like-front/src/main/java/com/mdd/front/service/impl/LoginServiceImpl.java @@ -215,8 +215,10 @@ public class LoginServiceImpl implements ILoginService { user.setLastLoginTime(System.currentTimeMillis() / 1000); userMapper.updateById(user); + String token = ToolsUtil.makeToken(); - RedisUtil.set(FrontConfig.frontendTokenKey+token, user.getId(), 7200); + int tokenValidTime = Integer.parseInt(YmlUtil.get("like.token-valid-time")); + RedisUtil.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime); LoginTokenVo vo = new LoginTokenVo(); vo.setId(user.getId()); diff --git a/server/like-front/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/server/like-front/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 6a59a7b2..75beb488 100644 --- a/server/like-front/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/server/like-front/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -4,6 +4,16 @@ "name": "like.upload-directory", "type": "java.lang.String", "description": "Description for like.upload-directory." + }, + { + "name": "like.token-valid-time", + "type": "java.lang.String", + "description": "Description for like.token-valid-time." + }, + { + "name": "like.token-renew-time", + "type": "java.lang.String", + "description": "Description for like.token-renew-time." } ] } \ No newline at end of file diff --git a/server/like-front/src/main/resources/application.yml b/server/like-front/src/main/resources/application.yml index e67b2aaf..6981b701 100644 --- a/server/like-front/src/main/resources/application.yml +++ b/server/like-front/src/main/resources/application.yml @@ -1,6 +1,11 @@ # 项目配置 like: - upload-directory: /www/uploads/likeadmin-java/ # 上传目录 + # 上传目录 + upload-directory: /www/uploads/likeadmin-java/ + # 登录有效时间 (单位秒) + token-valid-time: 7200 + # 登录续签时间 (不足以下秒数续签) + token-renew-time: 1800 # 服务配置 server: