Commit 86b13e14 authored by 唐峰's avatar 唐峰

用户资料和用户token操作相关改造2

parent ff3adc54
package cn.quantgroup.xyqb.controller; package cn.quantgroup.xyqb.controller;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.constant.UserConstant;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.session.SessionStruct; import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.util.IpUtil; import cn.quantgroup.xyqb.util.IpUtil;
...@@ -20,6 +22,8 @@ import static cn.quantgroup.xyqb.session.XyqbSessionContextHolder.*; ...@@ -20,6 +22,8 @@ import static cn.quantgroup.xyqb.session.XyqbSessionContextHolder.*;
*/ */
public interface IBaseController { public interface IBaseController {
@Deprecated @Deprecated
default User getCurrentUser() { default User getCurrentUser() {
SessionStruct session = getXSession(); SessionStruct session = getXSession();
...@@ -50,6 +54,14 @@ public interface IBaseController { ...@@ -50,6 +54,14 @@ public interface IBaseController {
return tenantId; return tenantId;
} }
default Integer getTenantId() {
String tenantIdStr = getRequest().getHeader(Constants.X_AUTH_TENANT);
if (StringUtils.isEmpty(tenantIdStr)) {
tenantIdStr = UserConstant.defaultTenantIdString;
}
return Integer.parseInt(tenantIdStr);
}
default SessionStruct getCurrentSessionFromRedis() { default SessionStruct getCurrentSessionFromRedis() {
return getXSessionFromRedis(); return getXSessionFromRedis();
} }
......
...@@ -247,7 +247,7 @@ public class SessionServiceImpl implements ISessionService { ...@@ -247,7 +247,7 @@ public class SessionServiceImpl implements ISessionService {
} }
@Override @Override
@CacheEvict(value = "userextinfocache", key = "'extinfo' + #userId", cacheManager = "cacheManager") @CacheEvict(value = "userextinfocache", key = "'extinfo' + #userId + '-' + #tenantId", cacheManager = "cacheManager")
public void deleteByUserId(long userId, Integer tenantId) { public void deleteByUserId(long userId, Integer tenantId) {
//1.删除session关联 //1.删除session关联
String setKey = getUserSessionSetKey(userId, tenantId); String setKey = getUserSessionSetKey(userId, tenantId);
......
...@@ -244,6 +244,7 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -244,6 +244,7 @@ public class UserServiceImpl implements IUserService, IBaseController {
// user.setPassword(PasswordUtil.MD5WithSalt(password)); // user.setPassword(PasswordUtil.MD5WithSalt(password));
user.setCipherPassword(BctyptPasswordUtil.BCryptWithSalt(password)); user.setCipherPassword(BctyptPasswordUtil.BCryptWithSalt(password));
user = userRepository.save(user); user = userRepository.save(user);
//cacheManager 配置的默认过期时间为3600s, 此处设置为1ms,是为了不缓存立刻过期 ?
stringRedisTemplate.expire("usercache:xyqbuser" + phoneNo, 1L, TimeUnit.MILLISECONDS); stringRedisTemplate.expire("usercache:xyqbuser" + phoneNo, 1L, TimeUnit.MILLISECONDS);
sessionService.deleteByUserId(user.getId(), tenantId); sessionService.deleteByUserId(user.getId(), tenantId);
return BctyptPasswordUtil.BCryptCheckPw(password, user.getCipherPassword()); return BctyptPasswordUtil.BCryptCheckPw(password, user.getCipherPassword());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment