换成单集群模式
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/xlzd/gotp"
|
||||
)
|
||||
@@ -23,6 +24,38 @@ func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 检查是否启用了 HTTPDNS 功能(全局用户注册设置中)
|
||||
var hasHTTPDNSFeature = false
|
||||
var defaultHttpdnsClusterId int64 = 0
|
||||
|
||||
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserRegisterConfig})
|
||||
if err == nil && len(resp.ValueJSON) > 0 {
|
||||
var config = userconfigs.DefaultUserRegisterConfig()
|
||||
if json.Unmarshal(resp.ValueJSON, config) == nil {
|
||||
hasHTTPDNSFeature = config.HTTPDNSIsOn
|
||||
if len(config.HTTPDNSDefaultClusterIds) > 0 {
|
||||
defaultHttpdnsClusterId = config.HTTPDNSDefaultClusterIds[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["hasHTTPDNSFeature"] = hasHTTPDNSFeature
|
||||
this.Data["httpdnsClusterId"] = defaultHttpdnsClusterId
|
||||
|
||||
// 加载所有 HTTPDNS 集群
|
||||
var httpdnsClusters = []maps.Map{}
|
||||
if hasHTTPDNSFeature {
|
||||
httpdnsClusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{})
|
||||
if err == nil {
|
||||
for _, c := range httpdnsClusterResp.GetClusters() {
|
||||
httpdnsClusters = append(httpdnsClusters, maps.Map{
|
||||
"id": c.GetId(),
|
||||
"name": c.GetName(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["httpdnsClusters"] = httpdnsClusters
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -35,8 +68,9 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Tel string
|
||||
Email string
|
||||
Remark string
|
||||
ClusterId int64
|
||||
FeaturesType string
|
||||
ClusterId int64
|
||||
HttpdnsClusterId int64
|
||||
FeaturesType string
|
||||
|
||||
// OTP
|
||||
OtpOn bool
|
||||
@@ -111,6 +145,28 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
|
||||
userId = createResp.UserId
|
||||
|
||||
// 如果表单选择了 HTTPDNS 关联集群,在这里予以保存
|
||||
if params.HttpdnsClusterId > 0 {
|
||||
httpdnsJSON, _ := json.Marshal([]int64{params.HttpdnsClusterId})
|
||||
_, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{
|
||||
UserId: userId,
|
||||
Username: params.Username,
|
||||
Password: params.Pass1,
|
||||
Fullname: params.Fullname,
|
||||
Mobile: params.Mobile,
|
||||
Tel: params.Tel,
|
||||
Email: params.Email,
|
||||
Remark: params.Remark,
|
||||
IsOn: true,
|
||||
NodeClusterId: params.ClusterId,
|
||||
HttpdnsClusterIdsJSON: httpdnsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 功能
|
||||
if teaconst.IsPlus {
|
||||
if params.FeaturesType == "default" {
|
||||
@@ -127,14 +183,41 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var featureCodes = config.Features
|
||||
if config.HTTPDNSIsOn && !lists.ContainsString(featureCodes, userconfigs.UserFeatureCodeHTTPDNS) {
|
||||
featureCodes = append(featureCodes, userconfigs.UserFeatureCodeHTTPDNS)
|
||||
}
|
||||
|
||||
_, err = this.RPC().UserRPC().UpdateUserFeatures(this.AdminContext(), &pb.UpdateUserFeaturesRequest{
|
||||
UserId: userId,
|
||||
FeatureCodes: config.Features,
|
||||
FeatureCodes: featureCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 自动关联默认 HTTPDNS 集群 (如果没有在表单中选择的话)
|
||||
if config.HTTPDNSIsOn && params.HttpdnsClusterId <= 0 && len(config.HTTPDNSDefaultClusterIds) > 0 {
|
||||
httpdnsJSON, _ := json.Marshal(config.HTTPDNSDefaultClusterIds)
|
||||
_, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{
|
||||
UserId: userId,
|
||||
Username: params.Username,
|
||||
Password: params.Pass1,
|
||||
Fullname: params.Fullname,
|
||||
Mobile: params.Mobile,
|
||||
Tel: params.Tel,
|
||||
Email: params.Email,
|
||||
Remark: params.Remark,
|
||||
IsOn: true,
|
||||
NodeClusterId: params.ClusterId,
|
||||
HttpdnsClusterIdsJSON: httpdnsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if params.FeaturesType == "all" {
|
||||
featuresResp, err := this.RPC().UserRPC().FindAllUserFeatureDefinitions(this.AdminContext(), &pb.FindAllUserFeatureDefinitionsRequest{})
|
||||
|
||||
Reference in New Issue
Block a user