diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java index 1dc2c6e2..b90c8002 100644 --- a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java +++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java @@ -58,7 +58,8 @@ public class TokenController if (StringUtils.isNotNull(loginUser)) { // 刷新令牌有效期 - return R.ok(tokenService.refreshToken(loginUser)); + tokenService.refreshToken(loginUser); + return R.ok(); } return R.ok(); } diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java index c5a6f358..0772abf2 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java @@ -4,13 +4,13 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.utils.IdUtils; import com.ruoyi.common.core.utils.ServletUtils; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.ip.IpUtils; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.system.api.model.LoginUser; @@ -81,6 +81,17 @@ public class TokenService return null; } + /** + * 设置用户身份信息 + */ + public void setLoginUser(LoginUser loginUser) + { + if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) + { + refreshToken(loginUser); + } + } + public void delLoginUser(String token) { if (StringUtils.isNotEmpty(token)) @@ -95,14 +106,13 @@ public class TokenService * * @param loginUser 登录信息 */ - public Long refreshToken(LoginUser loginUser) + public void refreshToken(LoginUser loginUser) { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + EXPIRE_TIME * MILLIS_SECOND); // 根据uuid将loginUser缓存 String userKey = getTokenKey(loginUser.getToken()); redisService.setCacheObject(userKey, loginUser, EXPIRE_TIME, TimeUnit.SECONDS); - return EXPIRE_TIME; } private String getTokenKey(String token) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysLogininforController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysLogininforController.java index c7b3760c..77cf00c7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysLogininforController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysLogininforController.java @@ -45,18 +45,18 @@ public class SysLogininforController extends BaseController return getDataTable(list); } - @Log(title = "登陆日志", businessType = BusinessType.EXPORT) + @Log(title = "登录日志", businessType = BusinessType.EXPORT) @PreAuthorize(hasPermi = "system:logininfor:export") @PostMapping("/export") public void export(HttpServletResponse response, SysLogininfor logininfor) throws IOException { List list = logininforService.selectLogininforList(logininfor); ExcelUtil util = new ExcelUtil(SysLogininfor.class); - util.exportExcel(response, list, "登陆日志"); + util.exportExcel(response, list, "登录日志"); } @PreAuthorize(hasPermi = "system:logininfor:remove") - @Log(title = "登陆日志", businessType = BusinessType.DELETE) + @Log(title = "登录日志", businessType = BusinessType.DELETE) @DeleteMapping("/{infoIds}") public AjaxResult remove(@PathVariable Long[] infoIds) { @@ -64,7 +64,7 @@ public class SysLogininforController extends BaseController } @PreAuthorize(hasPermi = "system:logininfor:remove") - @Log(title = "登陆日志", businessType = BusinessType.DELETE) + @Log(title = "登录日志", businessType = BusinessType.DELETE) @DeleteMapping("/clean") public AjaxResult clean() { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java index 56f8fbe5..19963417 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java @@ -10,8 +10,10 @@ import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.service.TokenService; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.service.ISysUserService; /** @@ -25,6 +27,9 @@ public class SysProfileController extends BaseController { @Autowired private ISysUserService userService; + + @Autowired + private TokenService tokenService; /** * 个人信息 @@ -49,6 +54,13 @@ public class SysProfileController extends BaseController { if (userService.updateUserProfile(user) > 0) { + LoginUser loginUser = tokenService.getLoginUser(); + // 更新缓存用户信息 + loginUser.getSysUser().setNickName(user.getNickName()); + loginUser.getSysUser().setPhonenumber(user.getPhonenumber()); + loginUser.getSysUser().setEmail(user.getEmail()); + loginUser.getSysUser().setSex(user.getSex()); + tokenService.setLoginUser(loginUser); return AjaxResult.success(); } return AjaxResult.error("修改个人信息异常,请联系管理员"); @@ -74,6 +86,10 @@ public class SysProfileController extends BaseController } if (userService.resetUserPwd(username, SecurityUtils.encryptPassword(newPassword)) > 0) { + // 更新缓存用户密码 + LoginUser loginUser = tokenService.getLoginUser(); + loginUser.getSysUser().setPassword(SecurityUtils.encryptPassword(newPassword)); + tokenService.setLoginUser(loginUser); return AjaxResult.success(); } return AjaxResult.error("修改密码异常,请联系管理员");