实现修改管理员信息功能

This commit is contained in:
GoEdgeLab
2020-10-14 19:42:32 +08:00
parent c31ef4f558
commit f558eec79e
8 changed files with 155 additions and 6 deletions

View File

@@ -1,6 +1,11 @@
package login
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
@@ -11,5 +16,63 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
adminResp, err := this.RPC().AdminRPC().FindEnabledAdmin(this.AdminContext(), &pb.FindEnabledAdminRequest{AdminId: this.AdminId()})
if err != nil {
this.ErrorPage(err)
return
}
admin := adminResp.Admin
if admin == nil {
this.NotFound("admin", this.AdminId())
return
}
this.Data["admin"] = maps.Map{
"username": admin.Username,
"fullname": admin.Fullname,
}
this.Show()
}
func (this *IndexAction) RunPost(params struct {
Username string
Password string
Password2 string
Must *actions.Must
}) {
params.Must.
Field("username", params.Username).
Require("请输入登录用户名").
Match(`^[a-zA-Z0-9_]+$`, "用户名中只能包含英文、数字或下划线")
existsResp, err := this.RPC().AdminRPC().CheckAdminUsername(this.AdminContext(), &pb.CheckAdminUsernameRequest{
AdminId: this.AdminId(),
Username: params.Username,
})
if err != nil {
this.ErrorPage(err)
return
}
if existsResp.Exists {
this.FailField("username", "此用户名已经被别的管理员使用,请换一个")
}
if len(params.Password) > 0 {
if params.Password != params.Password2 {
this.FailField("password2", "两次输入的密码不一致")
}
}
_, err = this.RPC().AdminRPC().UpdateAdminLogin(this.AdminContext(), &pb.UpdateAdminLoginRequest{
AdminId: this.AdminId(),
Username: params.Username,
Password: params.Password,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(settingutils.NewHelper("login")).
Prefix("/settings/login").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -1,6 +1,11 @@
package profile
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
@@ -11,5 +16,41 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
adminResp, err := this.RPC().AdminRPC().FindEnabledAdmin(this.AdminContext(), &pb.FindEnabledAdminRequest{AdminId: this.AdminId()})
if err != nil {
this.ErrorPage(err)
return
}
admin := adminResp.Admin
if admin == nil {
this.NotFound("admin", this.AdminId())
return
}
this.Data["admin"] = maps.Map{
"fullname": admin.Fullname,
}
this.Show()
}
func (this *IndexAction) RunPost(params struct {
Fullname string
Must *actions.Must
}) {
params.Must.
Field("fullname", params.Fullname).
Require("请输入你的姓名")
_, err := this.RPC().AdminRPC().UpdateAdmin(this.AdminContext(), &pb.UpdateAdminRequest{
AdminId: this.AdminId(),
Fullname: params.Fullname,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(settingutils.NewHelper("profile")).
Prefix("/settings/profile").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -1,3 +1,30 @@
{$layout}
<p class="comment">此功能暂未开放,敬请期待。</p>
<div class="margin"></div>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<table class="ui table definition selectable">
<tr>
<td class="title">登录用户名 *</td>
<td>
<input type="text" name="username" maxlength="50" v-model="admin.username" ref="focus"/>
<p class="comment">只能含有英文、数字或下划线。</p>
</td>
</tr>
<tr>
<td>登录密码</td>
<td>
<input type="password" name="password" maxlength="50"/>
<p class="comment">不填表示保留原有密码。</p>
</td>
</tr>
<tr>
<td>确认密码</td>
<td>
<input type="password" name="password2" maxlength="50"/>
<p class="comment">不填表示保留原有密码。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -1,3 +1,15 @@
{$layout}
<p class="comment">此功能暂未开放,敬请期待。</p>
<div class="margin"></div>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<table class="ui table definition selectable">
<tr>
<td class="title">你的姓名 *</td>
<td>
<input type="text" name="fullname" maxlength="50" ref="focus" v-model="admin.fullname"/>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})