This commit is contained in:
zhangchenbiao
2023-06-09 10:02:00 +08:00
parent 0b0e2d3f9e
commit 7734a4fbcc
7 changed files with 21 additions and 10 deletions

View File

@@ -24,5 +24,10 @@ public class CurrentUser {
*/
private Boolean isAdmin;
/**
* 头像
*/
private String avatar;
private SysRoleDO sysRoleDO;
}

View File

@@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils;
/**
*
*/
public class UserContext {
public class CurrentUserContext {
private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

View File

@@ -41,7 +41,7 @@ public class LoginServiceImpl implements LoginService {
private RedisUtilPool redisUtilPool;
@Resource
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
@Value("${corpId:null}")
@Value("${corp.id:null}")
private String corpId;
@Override
@@ -78,13 +78,14 @@ public class LoginServiceImpl implements LoginService {
currentUser.setIsAdmin(enterpriseUser.getIsAdmin());
currentUser.setSysRoleDO(sysRole);
currentUser.setCorpId(corpId);
currentUser.setAvatar(enterpriseUser.getAvatar());
//生成令牌
RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
String token = randomNumberGenerator.nextBytes().toHex();
String refreshToken = randomNumberGenerator.nextBytes().toHex();
currentUser.setName(enterpriseUser.getName());
currentUser.setAccessToken(token);
redisUtilPool.setString(CommonConstants.ACCESS_TOKEN_KEY + ":" + token, JSON.toJSONString(currentUser), CommonConstants.ACTION_TOKEN_EXPIRE);
redisUtilPool.setString(CommonConstants.ACCESS_TOKEN_KEY + ":" + token, JSON.toJSONString(currentUser), CommonConstants.ACCESS_TOKEN_EXPIRE);
redisUtilPool.setString(currentUser.getUserId(), token);
redisUtilPool.setString(CommonConstants.REFRESH_TOKEN_KEY+":"+refreshToken,JSON.toJSONString(refreshUser), CommonConstants.REFRESH_TOKEN_EXPIRE);
log.info("[" + enterpriseUser.getName() + "; action_token"+ token + "; userId" + currentUser.getUserId() +"]登入系统成功");