mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-03 09:36:37 +08:00
增加用户系统界面管理、用户可以设置关联集群
This commit is contained in:
@@ -17,6 +17,12 @@ func init() {
|
||||
GetPost("/create", new(CreateAction)).
|
||||
Post("/sync", new(SyncAction)).
|
||||
Post("/checkChange", new(CheckChangeAction)).
|
||||
|
||||
// 只要登录即可访问的Action
|
||||
EndHelpers().
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeCommon)).
|
||||
Post("/options", new(OptionsAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
30
internal/web/actions/default/clusters/options.go
Normal file
30
internal/web/actions/default/clusters/options.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type OptionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *OptionsAction) RunPost(params struct{}) {
|
||||
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
clusterMaps := []maps.Map{}
|
||||
for _, cluster := range clustersResp.Clusters {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
})
|
||||
}
|
||||
this.Data["clusters"] = clusterMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func (this *PricesAction) formatBits(bits int64) string {
|
||||
} else if bits < 1_000_000_000_000_000 {
|
||||
sizeHuman = fmt.Sprintf("%.2fTBPS", float64(bits)/1000/1000/1000/1000)
|
||||
} else {
|
||||
sizeHuman = fmt.Sprintf("%.2fPTBPS", float64(bits)/1000/1000/1000/1000/1000)
|
||||
sizeHuman = fmt.Sprintf("%.2fPBPS", float64(bits)/1000/1000/1000/1000/1000)
|
||||
}
|
||||
return sizeHuman
|
||||
}
|
||||
|
||||
@@ -13,6 +13,4 @@ func (this *IndexAction) Init() {
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// TODO 暂时先跳转到账单页,将来做成Dashboard
|
||||
this.RedirectURL("/finance/bills")
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.Data["token"] = stringutil.Md5(TokenSalt+timestamp) + timestamp
|
||||
this.Data["from"] = params.From
|
||||
|
||||
config, err := configloaders.LoadUIConfig()
|
||||
config, err := configloaders.LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
|
||||
@@ -30,7 +30,8 @@ func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool)
|
||||
var adminId = session.GetInt64("adminId")
|
||||
if configloaders.AllowModule(adminId, configloaders.AdminModuleCodeSetting) {
|
||||
tabbar.Add("Web服务", "", "/settings/server", "", this.tab == "server")
|
||||
tabbar.Add("界面设置", "", "/settings/ui", "", this.tab == "ui")
|
||||
tabbar.Add("管理界面设置", "", "/settings/ui", "", this.tab == "ui")
|
||||
tabbar.Add("用户界面设置", "", "/settings/user-ui", "", this.tab == "userUI")
|
||||
tabbar.Add("安全设置", "", "/settings/security", "", this.tab == "security")
|
||||
tabbar.Add("IP库", "", "/settings/ip-library", "", this.tab == "ipLibrary")
|
||||
tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package server
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
@@ -15,7 +15,7 @@ func (this *IndexAction) Init() {
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
config, err := configloaders.LoadUIConfig()
|
||||
config, err := configloaders.LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
@@ -41,7 +41,7 @@ func (this *IndexAction) RunPost(params struct {
|
||||
Field("adminSystemName", params.AdminSystemName).
|
||||
Require("请输入管理员系统名称")
|
||||
|
||||
config, err := configloaders.LoadUIConfig()
|
||||
config, err := configloaders.LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
@@ -51,7 +51,7 @@ func (this *IndexAction) RunPost(params struct {
|
||||
config.ShowOpenSourceInfo = params.ShowOpenSourceInfo
|
||||
config.ShowVersion = params.ShowVersion
|
||||
config.Version = params.Version
|
||||
err = configloaders.UpdateUIConfig(config)
|
||||
err = configloaders.UpdateAdminUIConfig(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package server
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
|
||||
61
internal/web/actions/default/settings/user-ui/index.go
Normal file
61
internal/web/actions/default/settings/user-ui/index.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package userui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
config, err := configloaders.LoadUserUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
ProductName string
|
||||
UserSystemName string
|
||||
ShowOpenSourceInfo bool
|
||||
ShowVersion bool
|
||||
Version string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("productName", params.ProductName).
|
||||
Require("请输入产品名称").
|
||||
Field("userSystemName", params.UserSystemName).
|
||||
Require("请输入管理员系统名称")
|
||||
|
||||
config, err := configloaders.LoadUserUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
config.ProductName = params.ProductName
|
||||
config.UserSystemName = params.UserSystemName
|
||||
config.ShowOpenSourceInfo = params.ShowOpenSourceInfo
|
||||
config.ShowVersion = params.ShowVersion
|
||||
config.Version = params.Version
|
||||
err = configloaders.UpdateUserUIConfig(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
19
internal/web/actions/default/settings/user-ui/init.go
Normal file
19
internal/web/actions/default/settings/user-ui/init.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package userui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeCommon)).
|
||||
Helper(settingutils.NewHelper("userUI")).
|
||||
Prefix("/settings/user-ui").
|
||||
GetPost("", new(IndexAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -20,14 +20,15 @@ func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Username string
|
||||
Pass1 string
|
||||
Pass2 string
|
||||
Fullname string
|
||||
Mobile string
|
||||
Tel string
|
||||
Email string
|
||||
Remark string
|
||||
Username string
|
||||
Pass1 string
|
||||
Pass2 string
|
||||
Fullname string
|
||||
Mobile string
|
||||
Tel string
|
||||
Email string
|
||||
Remark string
|
||||
ClusterId int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
@@ -60,6 +61,10 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Field("fullname", params.Fullname).
|
||||
Require("请输入全名")
|
||||
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择关联集群")
|
||||
}
|
||||
|
||||
if len(params.Mobile) > 0 {
|
||||
params.Must.
|
||||
Field("mobile", params.Mobile).
|
||||
@@ -72,14 +77,15 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().UserRPC().CreateUser(this.AdminContext(), &pb.CreateUserRequest{
|
||||
Username: params.Username,
|
||||
Password: params.Pass1,
|
||||
Fullname: params.Fullname,
|
||||
Mobile: params.Mobile,
|
||||
Tel: params.Tel,
|
||||
Email: params.Email,
|
||||
Remark: params.Remark,
|
||||
Source: "admin:" + numberutils.FormatInt64(this.AdminId()),
|
||||
Username: params.Username,
|
||||
Password: params.Pass1,
|
||||
Fullname: params.Fullname,
|
||||
Mobile: params.Mobile,
|
||||
Tel: params.Tel,
|
||||
Email: params.Email,
|
||||
Remark: params.Remark,
|
||||
Source: "admin:" + numberutils.FormatInt64(this.AdminId()),
|
||||
ClusterId: params.ClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -34,6 +34,13 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
userMaps := []maps.Map{}
|
||||
for _, user := range usersResp.Users {
|
||||
var clusterMap maps.Map = nil
|
||||
if user.Cluster != nil {
|
||||
clusterMap = maps.Map{
|
||||
"id": user.Cluster.Id,
|
||||
"name": user.Cluster.Name,
|
||||
}
|
||||
}
|
||||
userMaps = append(userMaps, maps.Map{
|
||||
"id": user.Id,
|
||||
"username": user.Username,
|
||||
@@ -43,6 +50,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
"mobile": user.Mobile,
|
||||
"tel": user.Tel,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", user.CreatedAt),
|
||||
"cluster": clusterMap,
|
||||
})
|
||||
}
|
||||
this.Data["users"] = userMaps
|
||||
|
||||
@@ -47,20 +47,26 @@ func (this *UpdateAction) RunGet(params struct {
|
||||
"isOn": user.IsOn,
|
||||
}
|
||||
|
||||
this.Data["clusterId"] = 0
|
||||
if user.Cluster != nil {
|
||||
this.Data["clusterId"] = user.Cluster.Id
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
UserId int64
|
||||
Username string
|
||||
Pass1 string
|
||||
Pass2 string
|
||||
Fullname string
|
||||
Mobile string
|
||||
Tel string
|
||||
Email string
|
||||
Remark string
|
||||
IsOn bool
|
||||
UserId int64
|
||||
Username string
|
||||
Pass1 string
|
||||
Pass2 string
|
||||
Fullname string
|
||||
Mobile string
|
||||
Tel string
|
||||
Email string
|
||||
Remark string
|
||||
IsOn bool
|
||||
ClusterId int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
@@ -109,15 +115,16 @@ func (this *UpdateAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
_, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{
|
||||
UserId: params.UserId,
|
||||
Username: params.Username,
|
||||
Password: params.Pass1,
|
||||
Fullname: params.Fullname,
|
||||
Mobile: params.Mobile,
|
||||
Tel: params.Tel,
|
||||
Email: params.Email,
|
||||
Remark: params.Remark,
|
||||
IsOn: params.IsOn,
|
||||
UserId: params.UserId,
|
||||
Username: params.Username,
|
||||
Password: params.Pass1,
|
||||
Fullname: params.Fullname,
|
||||
Mobile: params.Mobile,
|
||||
Tel: params.Tel,
|
||||
Email: params.Email,
|
||||
Remark: params.Remark,
|
||||
IsOn: params.IsOn,
|
||||
ClusterId: params.ClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -35,6 +35,14 @@ func (this *UserAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
var clusterMap maps.Map = nil
|
||||
if user.Cluster != nil {
|
||||
clusterMap = maps.Map{
|
||||
"id": user.Cluster.Id,
|
||||
"name": user.Cluster.Name,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["user"] = maps.Map{
|
||||
"id": user.Id,
|
||||
"username": user.Username,
|
||||
@@ -44,6 +52,7 @@ func (this *UserAction) RunGet(params struct {
|
||||
"remark": user.Remark,
|
||||
"mobile": user.Mobile,
|
||||
"isOn": user.IsOn,
|
||||
"cluster": clusterMap,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
|
||||
@@ -74,7 +74,7 @@ func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
return true
|
||||
}
|
||||
|
||||
config, err := configloaders.LoadUIConfig()
|
||||
config, err := configloaders.LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
action.WriteString(err.Error())
|
||||
return false
|
||||
|
||||
@@ -86,6 +86,7 @@ import (
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/ui"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/upgrade"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-nodes"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-ui"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/setup"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ui"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users"
|
||||
|
||||
Reference in New Issue
Block a user