修改用户个人资料/密码同步缓存信息

pull/24/head
RuoYi 4 years ago
parent 6b74ea676c
commit c2bd0ace6e

@ -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();
}

@ -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)

@ -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<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(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()
{

@ -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("修改密码异常,请联系管理员");

Loading…
Cancel
Save