fix(user): replace 'user' type with 'visitor' in user creation

refactor(session): improve token expiration handling in GetTokenInfo

chore: add /dist to gitignore
This commit is contained in:
2026-05-05 15:35:04 +08:00
parent a2869c1e0e
commit cdeaa5bacc
3 changed files with 14 additions and 5 deletions
+1
View File
@@ -41,6 +41,7 @@ go.work.sum
/frp_client /frp_client
/configs /configs
/dist
agent.md agent.md
super-frpc super-frpc
super-frpc.exe super-frpc.exe
+2 -2
View File
@@ -312,8 +312,8 @@ func CreateUserHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if req.Type != "admin" && req.Type != "user" && req.Type != "superuser" { if req.Type != "admin" && req.Type != "visitor" && req.Type != "superuser" {
utils.SendErrorResponse(w, http.StatusBadRequest, "Invalid type: must be 'admin' or 'user' or '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)) postLog.Warning(fmt.Sprintf("[CreateUserHandler] CreateUser failed: invalid type: %s", req.Type))
return return
} }
+11 -3
View File
@@ -121,14 +121,22 @@ func RemoveToken(userID int) {
func GetTokenInfo(userID int) (*TokenInfo, error) { func GetTokenInfo(userID int) (*TokenInfo, error) {
tokenMux.RLock() tokenMux.RLock()
defer tokenMux.RUnlock()
tokenInfo, exists := tokenMap[userID] tokenInfo, exists := tokenMap[userID]
if !exists { if !exists {
tokenMux.RUnlock()
return nil, fmt.Errorf("Token not found for userID %d", userID) 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 return tokenInfo, nil
} }