From fcb64a34bd44f9c72b74994af34e33da8b2cce01 Mon Sep 17 00:00:00 2001 From: smail Date: Sun, 13 Sep 2026 04:24:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(protocols):=20=E4=BF=AE=E5=A4=8D=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=8D=8F=E8=AE=AE=E6=8E=88=E6=9D=83=E7=A0=81?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E9=AA=8C=E8=AF=81=E5=90=8E=E8=A7=A3=E5=AF=86?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/controllers/security.go | 6 ++++++ backend/services/credentials/protocol.go | 11 +++++++---- .../ThirdPartyAuthorization.js | 7 ++++++- .../ThirdPartyAuthorization.vue | 12 ++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/backend/controllers/security.go b/backend/controllers/security.go index 6fae27d..378fff7 100644 --- a/backend/controllers/security.go +++ b/backend/controllers/security.go @@ -164,12 +164,18 @@ func LoadSecurityContext(ctx *context.Context) { func credentialRuntime() *credentials.Service { if service := currentSecurityRuntime().credentials; service != nil { + if service.VaultRoot() == "" && config.ROOT_PATH != "" { + service.SetVaultRoot(config.ROOT_PATH) + } return service } if db.Instance == nil { return nil } service, _ := credentials.NewService(db.Instance) + if service != nil && config.ROOT_PATH != "" { + service.SetVaultRoot(config.ROOT_PATH) + } return service } diff --git a/backend/services/credentials/protocol.go b/backend/services/credentials/protocol.go index 26baf4d..6c54756 100644 --- a/backend/services/credentials/protocol.go +++ b/backend/services/credentials/protocol.go @@ -32,6 +32,7 @@ type ProtocolCredentialStatus struct { Protocol string `json:"protocol"` Enabled bool `json:"enabled"` Configured bool `json:"configured"` + CanReveal bool `json:"can_reveal"` CreatedAt *time.Time `json:"created_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` LastUsedAt *time.Time `json:"last_used_at,omitempty"` @@ -75,6 +76,7 @@ func (s *Service) ListProtocolCredentials(userID int) ([]ProtocolCredentialStatu updatedAt := item.UpdatedAt status.Enabled = item.Enabled status.Configured = item.CodeHash != "" && item.RevokedAt == nil + status.CanReveal = item.CodeCiphertext != "" && item.RevokedAt == nil status.CreatedAt = &createdAt status.UpdatedAt = &updatedAt status.LastUsedAt = item.LastUsedAt @@ -255,11 +257,12 @@ func (s *Service) RevealProtocolCodes(userID int) (map[string]string, error) { if userID <= 0 { return nil, ErrInvalidUser } - if s.vaultRoot == "" { - return make(map[string]string), nil - } s.mu.Lock() defer s.mu.Unlock() + vaultRoot := s.vaultRoot + if vaultRoot == "" { + return make(map[string]string), nil + } var items []models.ProtocolCredential if err := s.engine.Where("user_id = ? AND enabled = ? AND revoked_at IS NULL", userID, true).Find(&items); err != nil { return nil, fmt.Errorf("load protocol credentials for reveal: %w", err) @@ -269,7 +272,7 @@ func (s *Service) RevealProtocolCodes(userID int) (map[string]string, error) { if item.CodeCiphertext == "" || item.CodeHash == "" { continue } - plain, err := credential.Decrypt(s.vaultRoot, item.CodeCiphertext) + plain, err := credential.Decrypt(vaultRoot, item.CodeCiphertext) if err != nil { continue } diff --git a/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js b/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js index 932b073..5c4752a 100644 --- a/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js +++ b/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js @@ -221,7 +221,12 @@ export function usePage() { Object.assign(revealedCodes, codes) codesRevealed.value = true closeVerifyDialog() - notify('安全验证通过,授权码已解密显示', 'success') + const count = Object.keys(codes).length + if (count > 0) { + notify(`安全验证通过,已解密显示 ${count} 个协议授权码`, 'success') + } else { + notify('安全验证通过,当前授权码未保留加密密文,可点击重新生成', 'warning') + } } catch (error) { notify(error?.message || '验证失败,请检查密码是否正确') } finally { diff --git a/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.vue b/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.vue index 0dddc4f..612bbff 100644 --- a/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.vue +++ b/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.vue @@ -70,6 +70,18 @@ 复制 +