思路:
第一次用戶登陸時生成UUID隨機數作爲token 查數據庫獲取用戶信息 保存redis中 key token value 用戶iduserId,
同時保存 key userId ,value用戶基本信息實體其中包含token字段息, 返回用戶基本信息,每次請求時傳token去查redis中是否存在
當第二次登陸時 先查數據庫獲取userId 拿到userId去redis裏查詢用戶實體是否存在,存在說明之前登陸過,拿到其中token,根據key token刪除保存在redis中的信息,redis保存新的 key token 和 key userId
登陸邏輯token處理
/**
* 登陸處理
* @param lmUserEntity
* @return
* @throws Exception
*/
public String handleLogin(LmUserEntity lmUserEntity) throws Exception {
LmUserEntity info = this.getUserByUserId(lmUserEntity.getUserId());
if (info != null) {
this.delToken(info.getToken());
logger.info("清除原登陸token:"+info.getToken());
}
String token=this.setLoginToken(lmUserEntity.getUserId());
logger.info("生成token:"+token);
lmUserEntity.setToken(token);
this.setUserByUserId(lmUserEntity);
return token;
}