x
Build docker and publish / build (20.15.1) (push) Successful in 6m35s

This commit is contained in:
2026-04-04 11:46:06 -07:00
parent e818ac8764
commit 62cf68b49b
5 changed files with 652 additions and 14 deletions
@@ -4,6 +4,7 @@ import (
"context"
"reflect"
"strings"
"github.com/perfect-panel/server/initialize"
"github.com/perfect-panel/server/internal/config"
@@ -44,8 +45,28 @@ func (l *UpdateRegisterConfigLogic) UpdateRegisterConfig(req *types.RegisterConf
fieldName := t.Field(i).Name
// Get the field value to string
fieldValue := tool.ConvertValueToString(v.Field(i))
// Update the site config
err = db.Model(&system.System{}).Where("`category` = 'register' and `key` = ?", fieldName).Update("value", fieldValue).Error
var existing system.System
queryErr := db.Where("`category` = ? and `key` = ?", "register", fieldName).First(&existing).Error
if queryErr != nil && !errors.Is(queryErr, gorm.ErrRecordNotFound) {
return queryErr
}
if errors.Is(queryErr, gorm.ErrRecordNotFound) {
fieldValue = l.defaultRegisterFieldValue(fieldName, fieldValue)
}
record := &system.System{
Category: "register",
Key: fieldName,
}
assignments := map[string]interface{}{
"value": fieldValue,
"type": inferRegisterSystemValueType(t.Field(i).Type.Kind()),
"desc": fieldName,
}
err = db.Where("`category` = ? and `key` = ?", "register", fieldName).
Assign(assignments).
FirstOrCreate(record).Error
if err != nil {
break
}
@@ -63,3 +84,28 @@ func (l *UpdateRegisterConfigLogic) UpdateRegisterConfig(req *types.RegisterConf
initialize.Register(l.svcCtx)
return nil
}
func inferRegisterSystemValueType(kind reflect.Kind) string {
switch kind {
case reflect.Bool:
return "bool"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return "int"
default:
return "string"
}
}
func (l *UpdateRegisterConfigLogic) defaultRegisterFieldValue(fieldName, fieldValue string) string {
switch fieldName {
case "EnableTrialEmailWhitelist":
return "true"
case "TrialEmailDomainWhitelist":
if strings.TrimSpace(fieldValue) != "" {
return fieldValue
}
return l.svcCtx.Config.Register.TrialEmailDomainWhitelist
default:
return fieldValue
}
}