190 lines
5.2 KiB
Go
190 lines
5.2 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
//go:build plus
|
|
|
|
package setting
|
|
|
|
import (
|
|
"encoding/json"
|
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"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"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "", "index")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
|
if !teaconst.IsPlus {
|
|
this.RedirectURL("/users")
|
|
return
|
|
}
|
|
|
|
// 当前配置
|
|
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserRegisterConfig})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
var config = userconfigs.DefaultUserRegisterConfig()
|
|
if len(resp.ValueJSON) > 0 {
|
|
err = json.Unmarshal(resp.ValueJSON, config)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
}
|
|
this.Data["config"] = config
|
|
|
|
// 功能列表
|
|
var featureMaps = []maps.Map{}
|
|
for _, feature := range userconfigs.FindAllUserFeatures() {
|
|
featureMaps = append(featureMaps, maps.Map{
|
|
"name": feature.Name,
|
|
"description": feature.Description,
|
|
"code": feature.Code,
|
|
"isChecked": lists.ContainsString(config.Features, feature.Code),
|
|
})
|
|
}
|
|
this.Data["features"] = featureMaps
|
|
|
|
// 当前高防
|
|
this.Data["adIsVisible"] = plus.AllowComponent(plus.ComponentCodeAntiDDoS)
|
|
|
|
// 当前默认的智能DNS设置
|
|
this.Data["nsIsVisible"] = plus.AllowComponent(plus.ComponentCodeNS)
|
|
|
|
this.Show()
|
|
}
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
IsOn bool
|
|
ComplexPassword bool
|
|
RequireVerification bool
|
|
RequireIdentity bool
|
|
|
|
CheckClientRegion bool
|
|
|
|
EmailVerificationIsOn bool
|
|
EmailVerificationShowNotice bool
|
|
EmailVerificationCanLogin bool
|
|
EmailVerificationSubject string
|
|
EmailVerificationBody string
|
|
|
|
EmailResetPasswordIsOn bool
|
|
EmailResetPasswordSubject string
|
|
EmailResetPasswordBody string
|
|
|
|
MobileVerificationIsOn bool
|
|
MobileVerificationShowNotice bool
|
|
MobileVerificationCanLogin bool
|
|
MobileVerificationForce bool
|
|
MobileVerificationBody string
|
|
|
|
CdnIsOn bool
|
|
ClusterId int64
|
|
Features []string
|
|
FeatureOp string
|
|
|
|
AdIsOn bool
|
|
|
|
NsIsOn bool
|
|
|
|
HttpdnsIsOn bool
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
defer this.CreateLogInfo(codes.User_LogUpdateUserGlobalSettings)
|
|
|
|
params.Must.
|
|
Field("clusterId", params.ClusterId).
|
|
Gt(0, "请选择一个集群")
|
|
|
|
var config = userconfigs.DefaultUserRegisterConfig()
|
|
{
|
|
// 先读取现有配置,避免保存时把未出现在当前表单里的字段重置为默认值
|
|
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
|
|
Code: systemconfigs.SettingCodeUserRegisterConfig,
|
|
})
|
|
if err == nil && len(resp.ValueJSON) > 0 {
|
|
_ = json.Unmarshal(resp.ValueJSON, config)
|
|
}
|
|
}
|
|
config.IsOn = params.IsOn
|
|
config.ComplexPassword = params.ComplexPassword
|
|
config.RequireVerification = params.RequireVerification
|
|
config.RequireIdentity = params.RequireIdentity
|
|
|
|
config.CheckClientRegion = params.CheckClientRegion
|
|
|
|
config.EmailVerification.IsOn = params.EmailVerificationIsOn
|
|
config.EmailVerification.CanLogin = params.EmailVerificationCanLogin
|
|
config.EmailVerification.Subject = params.EmailVerificationSubject
|
|
config.EmailVerification.Body = params.EmailVerificationBody
|
|
config.EmailVerification.ShowNotice = params.EmailVerificationShowNotice
|
|
|
|
config.MobileVerification.IsOn = params.MobileVerificationIsOn
|
|
config.MobileVerification.CanLogin = params.MobileVerificationCanLogin
|
|
config.MobileVerification.Force = params.MobileVerificationForce
|
|
config.MobileVerification.Body = params.MobileVerificationBody
|
|
config.MobileVerification.ShowNotice = params.MobileVerificationShowNotice
|
|
|
|
config.EmailResetPassword.IsOn = params.EmailResetPasswordIsOn
|
|
config.EmailResetPassword.Subject = params.EmailResetPasswordSubject
|
|
config.EmailResetPassword.Body = params.EmailResetPasswordBody
|
|
|
|
config.CDNIsOn = params.CdnIsOn
|
|
config.ClusterId = params.ClusterId
|
|
config.Features = params.Features
|
|
|
|
config.ADIsOn = params.AdIsOn
|
|
|
|
config.NSIsOn = params.NsIsOn
|
|
config.HTTPDNSIsOn = params.HttpdnsIsOn
|
|
|
|
configJSON, err := json.Marshal(config)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
|
Code: systemconfigs.SettingCodeUserRegisterConfig,
|
|
ValueJSON: configJSON,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
featureOp := params.FeatureOp
|
|
if featureOp != "overwrite" && featureOp != "append" && featureOp != "keep" {
|
|
featureOp = "keep"
|
|
}
|
|
|
|
if featureOp != "keep" {
|
|
_, err = this.RPC().UserRPC().UpdateAllUsersFeatures(this.AdminContext(), &pb.UpdateAllUsersFeaturesRequest{
|
|
FeatureCodes: params.Features,
|
|
Overwrite: featureOp == "overwrite",
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
this.Success()
|
|
}
|