mirror of https://gitee.com/stylefeng/roses
【auth】【system】增加updateSession接口,更新头像会刷新缓存
parent
604d6027b3
commit
26a79e6c21
|
@ -26,6 +26,16 @@ public interface SessionManagerApi {
|
|||
*/
|
||||
void createSession(String token, LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 更新当前会话的loginUser对象的内容
|
||||
*
|
||||
* @param token 用户的当前token
|
||||
* @param loginUser 新的登录用户信息
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/9 10:43
|
||||
*/
|
||||
void updateSession(String token, LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 通过token获取会话
|
||||
*
|
||||
|
|
|
@ -11,7 +11,6 @@ import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
|||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -86,6 +85,18 @@ public class DefaultSessionManager implements SessionManagerApi {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSession(String token, LoginUser loginUser) {
|
||||
LoginUser session = this.getSession(token);
|
||||
|
||||
// 该用户session为空不能更新
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
loginUserCache.put(token, loginUser, sessionExpiredSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getSession(String token) {
|
||||
return loginUserCache.get(token);
|
||||
|
@ -173,4 +184,5 @@ public class DefaultSessionManager implements SessionManagerApi {
|
|||
public List<LoginUser> onlineUserList() {
|
||||
return new ArrayList<>(loginUserCache.getAllValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class SysUserRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "userId不能为空", groups = {edit.class, delete.class, detail.class, grantRole.class, grantData.class, updateInfo.class, resetPwd.class, changeStatus.class, updateAvatar.class})
|
||||
@NotNull(message = "userId不能为空", groups = {edit.class, delete.class, detail.class, grantRole.class, grantData.class, updateInfo.class, resetPwd.class, changeStatus.class})
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
|||
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
|
@ -216,9 +217,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
@Override
|
||||
public void updateAvatar(SysUserRequest sysUserRequest) {
|
||||
|
||||
// 新头像文件id
|
||||
Long fileId = sysUserRequest.getAvatar();
|
||||
|
||||
// 从当前用户获取用户id
|
||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||
sysUserRequest.setUserId(loginUser.getUserId());
|
||||
|
||||
// 更新用户头像
|
||||
SysUser sysUser = this.querySysUser(sysUserRequest);
|
||||
sysUser.setAvatar(sysUserRequest.getAvatar());
|
||||
sysUser.setAvatar(fileId);
|
||||
this.updateById(sysUser);
|
||||
|
||||
// 更新当前用户的session信息
|
||||
SimpleUserInfo simpleUserInfo = loginUser.getSimpleUserInfo();
|
||||
simpleUserInfo.setAvatar(fileId);
|
||||
sessionManagerApi.updateSession(LoginContext.me().getToken(), loginUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue