From d2e68ba422d491f73e520ad8a2441c8a9f3481fd Mon Sep 17 00:00:00 2001 From: truthhun <1272881215@qq.com> Date: Fri, 10 Nov 2023 16:39:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=81=E5=AF=86=E4=BF=A1=E6=81=AF=E7=94=A8?= =?UTF-8?q?=E6=98=9F=E5=8F=B7=E6=9B=BF=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/config.go | 19 ++++++++++--------- model/config.go | 3 ++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/biz/config.go b/biz/config.go index a4672bd..a3f87f3 100644 --- a/biz/config.go +++ b/biz/config.go @@ -51,9 +51,10 @@ func (s *ConfigAPIService) UpdateConfig(ctx context.Context, req *pb.Configs) (* doesUpdateSEO := false isEmail := false for idx, cfg := range cfgs { - if cfg.Category == model.ConfigCategoryEmail && cfg.Name == model.ConfigEmailPassword && cfg.Value == "******" { - // 6个星号,不修改密码 - cfgs[idx].Value = s.dbModel.GetConfigOfEmail(model.ConfigEmailPassword).Password + if cfg.Value == "******" { + // 6个星号,不修改原值 + exist, _ := s.dbModel.GetConfigByNameCategory(cfg.Name, cfg.Category) + cfgs[idx].Value = exist.Value } isEmail = isEmail || cfg.Category == model.ConfigCategoryEmail if cfg.Category == model.ConfigCategorySystem { @@ -101,15 +102,15 @@ func (s *ConfigAPIService) ListConfig(ctx context.Context, req *pb.ListConfigReq return nil, status.Error(codes.Internal, err.Error()) } - var pbConfigs []*pb.Config - util.CopyStruct(&configs, &pbConfigs) - - for idx, cfg := range pbConfigs { - if cfg.Category == model.ConfigCategoryEmail && cfg.Name == model.ConfigEmailPassword { - pbConfigs[idx].Value = "******" + for idx, cfg := range configs { + if cfg.IsSecret { + configs[idx].Value = "******" } } + var pbConfigs []*pb.Config + util.CopyStruct(&configs, &pbConfigs) + return &pb.Configs{Config: pbConfigs}, nil } diff --git a/model/config.go b/model/config.go index 3704063..7c8e70e 100644 --- a/model/config.go +++ b/model/config.go @@ -63,6 +63,7 @@ type Config struct { Options string `form:"options" json:"options,omitempty" gorm:"column:options;type:text;comment:针对checkbox等的枚举值;"` CreatedAt *time.Time `form:"created_at" json:"created_at,omitempty" gorm:"column:created_at;type:datetime;comment:创建时间;"` UpdatedAt *time.Time `form:"updated_at" json:"updated_at,omitempty" gorm:"column:updated_at;type:datetime;comment:更新时间;"` + IsSecret bool `form:"is_secret" json:"is_secret,omitempty" gorm:"column:is_secret;type:tinyint(1);size:1;default:0;comment:是否是私密信息;"` } func (Config) TableName() string { @@ -735,7 +736,7 @@ func (m *DBModel) initConfig() (err error) { {Category: ConfigCategoryEmail, Name: ConfigEmailIsTLS, Label: "是否启用TLS", Value: "true", Placeholder: "如果是TLS端口,请启用", InputType: InputTypeSwitch, Sort: 40, Options: ""}, {Category: ConfigCategoryEmail, Name: ConfigEmailFromName, Label: "发件人名称", Value: "", Placeholder: "请输入您要展示的发件人名称", InputType: InputTypeText, Sort: 50, Options: ""}, {Category: ConfigCategoryEmail, Name: ConfigEmailUsername, Label: "SMTP 账号", Value: "", Placeholder: "请输入您的邮箱账户", InputType: InputTypeText, Sort: 60, Options: ""}, - {Category: ConfigCategoryEmail, Name: ConfigEmailPassword, Label: "SMTP 密码", Value: "", Placeholder: "请输入您的邮箱密码", InputType: InputTypePassword, Sort: 70, Options: ""}, + {Category: ConfigCategoryEmail, Name: ConfigEmailPassword, Label: "SMTP 密码", Value: "", Placeholder: "请输入您的邮箱密码", InputType: InputTypePassword, Sort: 70, Options: "", IsSecret: true}, {Category: ConfigCategoryEmail, Name: ConfigEmailDuration, Label: "邮件有效期", Value: "30", Placeholder: "找回密码时链接有效期,默认为30,表示30分钟", InputType: InputTypeNumber, Sort: 80, Options: ""}, {Category: ConfigCategoryEmail, Name: ConfigEmailSecret, Label: "签名密钥", Value: "moredoc", Placeholder: "找回密码链接签名密钥", InputType: InputTypeText, Sort: 80, Options: ""}, {Category: ConfigCategoryEmail, Name: ConfigEmailTestEmail, Label: "测试邮箱", Value: "", Placeholder: "用于每次变更配置时保存发送测试邮件", InputType: InputTypeText, Sort: 90, Options: ""},