mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
系统用户增加是否允许登录选项
This commit is contained in:
@@ -89,6 +89,7 @@ func (this *AdminDAO) CheckAdminPassword(tx *dbs.Tx, username string, encryptedP
|
||||
Attr("password", encryptedPassword).
|
||||
Attr("state", AdminStateEnabled).
|
||||
Attr("isOn", true).
|
||||
Attr("canLogin", 1).
|
||||
ResultPk().
|
||||
FindInt64Col(0)
|
||||
}
|
||||
@@ -122,11 +123,12 @@ func (this *AdminDAO) UpdateAdminPassword(tx *dbs.Tx, adminId int64, password st
|
||||
}
|
||||
|
||||
// 创建管理员
|
||||
func (this *AdminDAO) CreateAdmin(tx *dbs.Tx, username string, password string, fullname string, isSuper bool, modulesJSON []byte) (int64, error) {
|
||||
func (this *AdminDAO) CreateAdmin(tx *dbs.Tx, username string, canLogin bool, password string, fullname string, isSuper bool, modulesJSON []byte) (int64, error) {
|
||||
op := NewAdminOperator()
|
||||
op.IsOn = true
|
||||
op.State = AdminStateEnabled
|
||||
op.Username = username
|
||||
op.CanLogin = canLogin
|
||||
op.Password = stringutil.Md5(password)
|
||||
op.Fullname = fullname
|
||||
op.IsSuper = isSuper
|
||||
@@ -155,7 +157,7 @@ func (this *AdminDAO) UpdateAdminInfo(tx *dbs.Tx, adminId int64, fullname string
|
||||
}
|
||||
|
||||
// 修改管理员详细信息
|
||||
func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, password string, fullname string, isSuper bool, modulesJSON []byte, isOn bool) error {
|
||||
func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, canLogin bool, password string, fullname string, isSuper bool, modulesJSON []byte, isOn bool) error {
|
||||
if adminId <= 0 {
|
||||
return errors.New("invalid adminId")
|
||||
}
|
||||
@@ -163,6 +165,7 @@ func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, pa
|
||||
op.Id = adminId
|
||||
op.Fullname = fullname
|
||||
op.Username = username
|
||||
op.CanLogin = canLogin
|
||||
if len(password) > 0 {
|
||||
op.Password = stringutil.Md5(password)
|
||||
}
|
||||
@@ -242,7 +245,7 @@ func (this *AdminDAO) CountAllEnabledAdmins(tx *dbs.Tx) (int64, error) {
|
||||
func (this *AdminDAO) ListEnabledAdmins(tx *dbs.Tx, offset int64, size int64) (result []*Admin, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(AdminStateEnabled).
|
||||
Result("id", "isOn", "username", "fullname", "isSuper", "createdAt").
|
||||
Result("id", "isOn", "username", "fullname", "isSuper", "createdAt", "canLogin").
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
DescPk().
|
||||
|
||||
@@ -12,6 +12,7 @@ type Admin struct {
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 状态
|
||||
Modules string `field:"modules"` // 允许的模块
|
||||
CanLogin uint8 `field:"canLogin"` // 是否可以登录
|
||||
}
|
||||
|
||||
type AdminOperator struct {
|
||||
@@ -25,6 +26,7 @@ type AdminOperator struct {
|
||||
UpdatedAt interface{} // 修改时间
|
||||
State interface{} // 状态
|
||||
Modules interface{} // 允许的模块
|
||||
CanLogin interface{} // 是否可以登录
|
||||
}
|
||||
|
||||
func NewAdminOperator() *AdminOperator {
|
||||
|
||||
@@ -181,6 +181,7 @@ func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnab
|
||||
IsSuper: admin.IsSuper == 1,
|
||||
Modules: pbModules,
|
||||
OtpLogin: pbOtpAuth,
|
||||
CanLogin: admin.CanLogin == 1,
|
||||
}
|
||||
return &pb.FindEnabledAdminResponse{Admin: result}, nil
|
||||
}
|
||||
@@ -206,7 +207,7 @@ func (this *AdminService) CreateOrUpdateAdmin(ctx context.Context, req *pb.Creat
|
||||
}
|
||||
return &pb.CreateOrUpdateAdminResponse{AdminId: adminId}, nil
|
||||
}
|
||||
adminId, err = models.SharedAdminDAO.CreateAdmin(tx, req.Username, req.Password, "管理员", true, nil)
|
||||
adminId, err = models.SharedAdminDAO.CreateAdmin(tx, req.Username, true, req.Password, "管理员", true, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -312,7 +313,7 @@ func (this *AdminService) CreateAdmin(ctx context.Context, req *pb.CreateAdminRe
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
adminId, err := models.SharedAdminDAO.CreateAdmin(tx, req.Username, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON)
|
||||
adminId, err := models.SharedAdminDAO.CreateAdmin(tx, req.Username, req.CanLogin, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -331,7 +332,7 @@ func (this *AdminService) UpdateAdmin(ctx context.Context, req *pb.UpdateAdminRe
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedAdminDAO.UpdateAdmin(tx, req.AdminId, req.Username, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON, req.IsOn)
|
||||
err = models.SharedAdminDAO.UpdateAdmin(tx, req.AdminId, req.Username, req.CanLogin, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -399,6 +400,7 @@ func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEna
|
||||
IsSuper: admin.IsSuper == 1,
|
||||
CreatedAt: int64(admin.CreatedAt),
|
||||
OtpLogin: pbOtpAuth,
|
||||
CanLogin: admin.CanLogin == 1,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user