mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
实现用户注册/审核功能
This commit is contained in:
@@ -378,6 +378,10 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
||||
"isActive": secondMenuItem == "traffic",
|
||||
"isOn": serverConfig.TrafficLimit != nil && serverConfig.TrafficLimit.IsOn,
|
||||
})
|
||||
|
||||
if serverConfig.Web != nil && serverConfig.Web.RequestScripts != nil {
|
||||
_ = serverConfig.Web.RequestScripts.Init()
|
||||
}
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "边缘脚本",
|
||||
"url": "/servers/server/settings/requestScripts?serverId=" + serverIdString,
|
||||
|
||||
@@ -36,7 +36,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
userMaps := []maps.Map{}
|
||||
var userMaps = []maps.Map{}
|
||||
for _, user := range usersResp.Users {
|
||||
var clusterMap maps.Map = nil
|
||||
if user.NodeCluster != nil {
|
||||
@@ -45,16 +45,20 @@ func (this *IndexAction) RunGet(params struct {
|
||||
"name": user.NodeCluster.Name,
|
||||
}
|
||||
}
|
||||
|
||||
userMaps = append(userMaps, maps.Map{
|
||||
"id": user.Id,
|
||||
"username": user.Username,
|
||||
"isOn": user.IsOn,
|
||||
"fullname": user.Fullname,
|
||||
"email": user.Email,
|
||||
"mobile": user.Mobile,
|
||||
"tel": user.Tel,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", user.CreatedAt),
|
||||
"cluster": clusterMap,
|
||||
"id": user.Id,
|
||||
"username": user.Username,
|
||||
"isOn": user.IsOn,
|
||||
"fullname": user.Fullname,
|
||||
"email": user.Email,
|
||||
"mobile": user.Mobile,
|
||||
"tel": user.Tel,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", user.CreatedAt),
|
||||
"cluster": clusterMap,
|
||||
"registeredIP": user.RegisteredIP,
|
||||
"isVerified": user.IsVerified,
|
||||
"isRejected": user.IsRejected,
|
||||
})
|
||||
}
|
||||
this.Data["users"] = userMaps
|
||||
|
||||
@@ -19,6 +19,7 @@ func init() {
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
GetPost("/features", new(FeaturesAction)).
|
||||
GetPost("/verifyPopup", new(VerifyPopupAction)).
|
||||
|
||||
// AccessKeys
|
||||
Prefix("/users/accessKeys").
|
||||
@@ -26,7 +27,6 @@ func init() {
|
||||
GetPost("/createPopup", new(accesskeys.CreatePopupAction)).
|
||||
Post("/delete", new(accesskeys.DeleteAction)).
|
||||
Post("/updateIsOn", new(accesskeys.UpdateIsOnAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ func (this *UserAction) RunGet(params struct {
|
||||
}) {
|
||||
err := userutils.InitUser(this.Parent(), params.UserId)
|
||||
if err != nil {
|
||||
if err == userutils.ErrUserNotFound {
|
||||
this.RedirectURL("/users")
|
||||
return
|
||||
}
|
||||
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
@@ -51,17 +56,35 @@ func (this *UserAction) RunGet(params struct {
|
||||
}
|
||||
countAccessKeys := countAccessKeyResp.Count
|
||||
|
||||
// IP地址
|
||||
var registeredRegion = ""
|
||||
if len(user.RegisteredIP) > 0 {
|
||||
regionResp, err := this.RPC().IPLibraryRPC().LookupIPRegion(this.AdminContext(), &pb.LookupIPRegionRequest{Ip: user.RegisteredIP})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if regionResp.IpRegion != nil {
|
||||
registeredRegion = regionResp.IpRegion.Summary
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["user"] = maps.Map{
|
||||
"id": user.Id,
|
||||
"username": user.Username,
|
||||
"fullname": user.Fullname,
|
||||
"email": user.Email,
|
||||
"tel": user.Tel,
|
||||
"remark": user.Remark,
|
||||
"mobile": user.Mobile,
|
||||
"isOn": user.IsOn,
|
||||
"cluster": clusterMap,
|
||||
"countAccessKeys": countAccessKeys,
|
||||
"id": user.Id,
|
||||
"username": user.Username,
|
||||
"fullname": user.Fullname,
|
||||
"email": user.Email,
|
||||
"tel": user.Tel,
|
||||
"remark": user.Remark,
|
||||
"mobile": user.Mobile,
|
||||
"isOn": user.IsOn,
|
||||
"cluster": clusterMap,
|
||||
"countAccessKeys": countAccessKeys,
|
||||
"isRejected": user.IsRejected,
|
||||
"rejectReason": user.RejectReason,
|
||||
"isVerified": user.IsVerified,
|
||||
"registeredIP": user.RegisteredIP,
|
||||
"registeredRegion": registeredRegion,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
var ErrUserNotFound = errors.New("not found user")
|
||||
|
||||
// InitUser 查找用户基本信息
|
||||
func InitUser(p *actionutils.ParentAction, userId int64) error {
|
||||
resp, err := p.RPC().UserRPC().FindEnabledUser(p.AdminContext(), &pb.FindEnabledUserRequest{UserId: userId})
|
||||
@@ -14,7 +16,7 @@ func InitUser(p *actionutils.ParentAction, userId int64) error {
|
||||
return err
|
||||
}
|
||||
if resp.User == nil {
|
||||
return errors.New("not found user")
|
||||
return ErrUserNotFound
|
||||
}
|
||||
|
||||
// AccessKey数量
|
||||
|
||||
56
internal/web/actions/default/users/verifyPopup.go
Normal file
56
internal/web/actions/default/users/verifyPopup.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type VerifyPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *VerifyPopupAction) RunGet(params struct {
|
||||
UserId int64
|
||||
}) {
|
||||
this.Data["userId"] = params.UserId
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *VerifyPopupAction) RunPost(params struct {
|
||||
UserId int64
|
||||
Result string
|
||||
RejectReason string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("审核用户:%d 结果:%s", params.UserId, params.Result)
|
||||
|
||||
if params.Result == "pass" {
|
||||
params.RejectReason = ""
|
||||
}
|
||||
|
||||
_, err := this.RPC().UserRPC().VerifyUser(this.AdminContext(), &pb.VerifyUserRequest{
|
||||
UserId: params.UserId,
|
||||
IsRejected: params.Result == "reject" || params.Result == "delete",
|
||||
RejectReason: params.RejectReason,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
if params.Result == "delete" {
|
||||
_, err = this.RPC().UserRPC().DeleteUser(this.AdminContext(), &pb.DeleteUserRequest{UserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user