ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
@@ -9,6 +9,7 @@ import io.seata.spring.annotation.GlobalTransactional; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import com.ruoyi.auth.form.LoginBody; import com.ruoyi.auth.form.RegisterBody; @@ -48,11 +49,11 @@ HashMap<String, Object> map = new HashMap<>(); map.put("token", tokenService.createToken(userInfo)); List<SysRole> roles = userInfo.getSysUser().getRoles(); // if(CollectionUtils.isEmpty(roles)){ // return R.fail("请关联角色!"); // } if(CollectionUtils.isEmpty(roles)){ return R.fail("请关联角色!"); } // map.put("roleName",roles.get(0).getRoleName()); map.put("roleName",roles.get(0).getRoleName()); map.put("info", userInfo); // 修改用户最后登录时间 SysUser sysUser = new SysUser(); ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java
@@ -94,7 +94,7 @@ public LoginUserApplet getLoginUserApplet() { LoginUserApplet loginUserAppletToken = getLoginUserAppletToken(ServletUtils.getRequest()); if (loginUserAppletToken == null) { throw new UserAppletException("登录失效,请重新登录!", 401); throw new RuntimeException("令牌已过期,请重新登录!"); } return loginUserAppletToken; } @@ -130,7 +130,11 @@ * @return 用户信息 */ public LoginUser getLoginUser() { return getLoginUser(ServletUtils.getRequest()); LoginUser loginUser = getLoginUser(ServletUtils.getRequest()); if (loginUser == null) { throw new RuntimeException("令牌已过期,请重新登录!"); } return loginUser; } /** @@ -209,10 +213,10 @@ public void refreshToken1(LoginUserApplet dto) { dto.setLoginTime(System.currentTimeMillis()); dto.setExpireTime(dto.getLoginTime() + expireTime * MILLIS_MINUTE); dto.setExpireTime(dto.getLoginTime() + expireAppletTime * MILLIS_MINUTE); // 根据uuid将loginUser缓存 String userKey = getTokenKey(dto.getToken()); redisService.setCacheObject(userKey, dto, expireTime, TimeUnit.MINUTES); redisService.setCacheObject(userKey, dto, expireAppletTime, TimeUnit.MINUTES); } private String getTokenKey(String token) {