From cdeaa5baccb017c4f58ed28800d1074cf55c1524 Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Tue, 5 May 2026 15:35:04 +0800 Subject: [PATCH] fix(user): replace 'user' type with 'visitor' in user creation refactor(session): improve token expiration handling in GetTokenInfo chore: add /dist to gitignore --- .gitignore | 1 + handlers/user.go | 4 ++-- session/session.go | 14 +++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1329c80..0f6d5f9 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ go.work.sum /frp_client /configs +/dist agent.md super-frpc super-frpc.exe diff --git a/handlers/user.go b/handlers/user.go index 5724039..5221175 100644 --- a/handlers/user.go +++ b/handlers/user.go @@ -312,8 +312,8 @@ func CreateUserHandler(w http.ResponseWriter, r *http.Request) { return } - if req.Type != "admin" && req.Type != "user" && req.Type != "superuser" { - utils.SendErrorResponse(w, http.StatusBadRequest, "Invalid type: must be 'admin' or 'user' or 'superuser'") + if req.Type != "admin" && req.Type != "visitor" && req.Type != "superuser" { + utils.SendErrorResponse(w, http.StatusBadRequest, "Invalid type: must be 'admin' or 'visitor' or 'superuser'") postLog.Warning(fmt.Sprintf("[CreateUserHandler] CreateUser failed: invalid type: %s", req.Type)) return } diff --git a/session/session.go b/session/session.go index 6f3c731..5a92490 100644 --- a/session/session.go +++ b/session/session.go @@ -121,14 +121,22 @@ func RemoveToken(userID int) { func GetTokenInfo(userID int) (*TokenInfo, error) { tokenMux.RLock() - defer tokenMux.RUnlock() - tokenInfo, exists := tokenMap[userID] if !exists { + tokenMux.RUnlock() return nil, fmt.Errorf("Token not found for userID %d", userID) - } + if time.Since(tokenInfo.CreatedAt) > tokenTTL { + tokenMux.RUnlock() + tokenMux.Lock() + delete(tokenMap, userID) + tokenMux.Unlock() + postLog.Debug(fmt.Sprintf("[GetTokenInfo] Removed expired token for userID %d during login check", userID)) + return nil, fmt.Errorf("Token expired for userID %d", userID) + } + tokenMux.RUnlock() + return tokenInfo, nil }