From 0afdc9cc89a33685906381d2809cc667d2169cb7 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Wed, 15 Apr 2026 11:30:21 +0800 Subject: [PATCH] 1 --- service/xboard/service.go | 21 +++++++++++++++++++-- service/xboard/service_test.go | 12 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/service/xboard/service.go b/service/xboard/service.go index c9b80038..13fab8f1 100644 --- a/service/xboard/service.go +++ b/service/xboard/service.go @@ -902,6 +902,10 @@ func (s *Service) syncUsers() { } for _, u := range users { + userName := u.Identifier() + if userName == "" { + continue + } key := s.resolveUserKey(u, isSS2022) if key == "" { continue @@ -914,9 +918,9 @@ func (s *Service) syncUsers() { s.logger.Info("User [", u.ID, "] ID[:", ss2022KeyLen, "]=", originalKey, " → b64_PSK=", key) } - newUsers[u.Email] = userData{ + newUsers[userName] = userData{ ID: u.ID, - Email: u.Email, + Email: userName, Key: key, Flow: u.Flow, } @@ -1084,6 +1088,19 @@ type XUser struct { Flow string `json:"flow"` } +func (u *XUser) Identifier() string { + if u.UUID != "" { + return u.UUID + } + if u.Email != "" { + return u.Email + } + if u.ID != 0 { + return strconv.Itoa(u.ID) + } + return "" +} + func (u *XUser) ResolveKey() string { if u.Passwd != "" { return u.Passwd diff --git a/service/xboard/service_test.go b/service/xboard/service_test.go index eb51d6c6..16971a33 100644 --- a/service/xboard/service_test.go +++ b/service/xboard/service_test.go @@ -15,6 +15,18 @@ func TestXUserResolveKeyPrefersPasswordFields(t *testing.T) { } } +func TestXUserIdentifierPrefersUUID(t *testing.T) { + user := XUser{ + ID: 7, + UUID: "uuid-value", + Email: "user@example.com", + } + + if got := user.Identifier(); got != "uuid-value" { + t.Fatalf("Identifier() = %q, want %q", got, "uuid-value") + } +} + func TestResolveUserKeyForSS2022CombinedPassword(t *testing.T) { service := &Service{ssServerKey: "master-key"} user := XUser{