mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-22 12:35:19 +08:00
[用户]实现对平台用户的增删改查
This commit is contained in:
91
internal/web/actions/default/users/createPopup.go
Normal file
91
internal/web/actions/default/users/createPopup.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Username string
|
||||
Pass1 string
|
||||
Pass2 string
|
||||
Fullname string
|
||||
Mobile string
|
||||
Tel string
|
||||
Email string
|
||||
Remark string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("username", params.Username).
|
||||
Require("请输入用户名").
|
||||
Match(`^[a-zA-Z0-9_]+$`, "用户名中只能含有英文、数字和下划线")
|
||||
|
||||
checkUsernameResp, err := this.RPC().UserRPC().CheckUsername(this.AdminContext(), &pb.CheckUsernameRequest{
|
||||
UserId: 0,
|
||||
Username: params.Username,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if checkUsernameResp.Exists {
|
||||
this.FailField("username", "此用户名已经被占用,请换一个")
|
||||
}
|
||||
|
||||
params.Must.
|
||||
Field("pass1", params.Pass1).
|
||||
Require("请输入密码").
|
||||
Field("pass2", params.Pass2).
|
||||
Require("请再次输入确认密码").
|
||||
Equal(params.Pass1, "两次输入的密码不一致")
|
||||
|
||||
params.Must.
|
||||
Field("fullname", params.Fullname).
|
||||
Require("请输入全名")
|
||||
|
||||
if len(params.Mobile) > 0 {
|
||||
params.Must.
|
||||
Field("mobile", params.Mobile).
|
||||
Mobile("请输入正确的手机号")
|
||||
}
|
||||
if len(params.Email) > 0 {
|
||||
params.Must.
|
||||
Field("email", params.Email).
|
||||
Email("请输入正确的电子邮箱")
|
||||
}
|
||||
|
||||
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()),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo("创建用户 %d", createResp.UserId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user