[系统用户]增加OTP动态密码二次认证

This commit is contained in:
GoEdgeLab
2020-12-24 17:15:53 +08:00
parent 89506a15c0
commit bf61b2a170
35 changed files with 532 additions and 137 deletions

View File

@@ -7,6 +7,8 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"github.com/xlzd/gotp"
)
type CreatePopupAction struct {
@@ -30,6 +32,9 @@ func (this *CreatePopupAction) RunPost(params struct {
ModuleCodes []string
IsSuper bool
// OTP
OtpOn bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
@@ -89,6 +94,24 @@ func (this *CreatePopupAction) RunPost(params struct {
return
}
// OTP
if params.OtpOn {
_, err = this.RPC().LoginRPC().UpdateLogin(this.AdminContext(), &pb.UpdateLoginRequest{Login: &pb.Login{
Id: 0,
Type: "otp",
ParamsJSON: maps.Map{
"secret": gotp.RandomSecret(16), // TODO 改成可以设置secret长度
}.AsJSON(),
IsOn: true,
AdminId: createResp.AdminId,
UserId: 0,
}})
if err != nil {
this.ErrorPage(err)
return
}
}
defer this.CreateLogInfo("创建系统用户 %d", createResp.AdminId)
// 通知更改