From 4652a124ca1b5faaec0eee478d0edf40b41055c4 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 19 Oct 2023 14:47:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=BB=B6=E8=BF=9Fsess?= =?UTF-8?q?ion=5Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/utils/token/token.go | 4 ++-- src/lib_features/account/account.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/framework/utils/token/token.go b/src/framework/utils/token/token.go index 6815eb2..b28462e 100644 --- a/src/framework/utils/token/token.go +++ b/src/framework/utils/token/token.go @@ -35,8 +35,8 @@ func Remove(tokenStr string) string { // Create 令牌生成 func Create(loginUser *vo.LoginUser, ilobArgs ...string) string { - // 生成用户唯一tokne32位 - loginUser.UUID = generate.Code(32) + // 生成用户唯一tokne16位 + loginUser.UUID = generate.Code(16) // 设置请求用户登录客户端 loginUser.IPAddr = ilobArgs[0] diff --git a/src/lib_features/account/account.go b/src/lib_features/account/account.go index 2bdfd8f..9e4e5ea 100644 --- a/src/lib_features/account/account.go +++ b/src/lib_features/account/account.go @@ -14,7 +14,13 @@ import ( func SessionToken(username, sourceAddr string) bool { token, _ := redis.Get("", "session_token") if token != "" { - return true + se, err := dborm.XormUpdateSessionShakeTime(token) + if se.AccountId != username || err != nil { + // 过期时间单位秒 配置1800是半小时 + expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second + redis.SetByExpire("", "session_token", token, expireTime) + return true + } } token = oauth.GenRandToken("omc") // Generate new token to session ID