Skip to content

Commit 219f361

Browse files
committed
系统用户增加是否允许登录选项
1 parent c04daa6 commit 219f361

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

internal/db/models/admin_dao.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (this *AdminDAO) CheckAdminPassword(tx *dbs.Tx, username string, encryptedP
8989
Attr("password", encryptedPassword).
9090
Attr("state", AdminStateEnabled).
9191
Attr("isOn", true).
92+
Attr("canLogin", 1).
9293
ResultPk().
9394
FindInt64Col(0)
9495
}
@@ -122,11 +123,12 @@ func (this *AdminDAO) UpdateAdminPassword(tx *dbs.Tx, adminId int64, password st
122123
}
123124

124125
// 创建管理员
125-
func (this *AdminDAO) CreateAdmin(tx *dbs.Tx, username string, password string, fullname string, isSuper bool, modulesJSON []byte) (int64, error) {
126+
func (this *AdminDAO) CreateAdmin(tx *dbs.Tx, username string, canLogin bool, password string, fullname string, isSuper bool, modulesJSON []byte) (int64, error) {
126127
op := NewAdminOperator()
127128
op.IsOn = true
128129
op.State = AdminStateEnabled
129130
op.Username = username
131+
op.CanLogin = canLogin
130132
op.Password = stringutil.Md5(password)
131133
op.Fullname = fullname
132134
op.IsSuper = isSuper
@@ -155,14 +157,15 @@ func (this *AdminDAO) UpdateAdminInfo(tx *dbs.Tx, adminId int64, fullname string
155157
}
156158

157159
// 修改管理员详细信息
158-
func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, password string, fullname string, isSuper bool, modulesJSON []byte, isOn bool) error {
160+
func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, canLogin bool, password string, fullname string, isSuper bool, modulesJSON []byte, isOn bool) error {
159161
if adminId <= 0 {
160162
return errors.New("invalid adminId")
161163
}
162164
op := NewAdminOperator()
163165
op.Id = adminId
164166
op.Fullname = fullname
165167
op.Username = username
168+
op.CanLogin = canLogin
166169
if len(password) > 0 {
167170
op.Password = stringutil.Md5(password)
168171
}
@@ -242,7 +245,7 @@ func (this *AdminDAO) CountAllEnabledAdmins(tx *dbs.Tx) (int64, error) {
242245
func (this *AdminDAO) ListEnabledAdmins(tx *dbs.Tx, offset int64, size int64) (result []*Admin, err error) {
243246
_, err = this.Query(tx).
244247
State(AdminStateEnabled).
245-
Result("id", "isOn", "username", "fullname", "isSuper", "createdAt").
248+
Result("id", "isOn", "username", "fullname", "isSuper", "createdAt", "canLogin").
246249
Offset(offset).
247250
Limit(size).
248251
DescPk().

internal/db/models/admin_model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Admin struct {
1212
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
1313
State uint8 `field:"state"` // 状态
1414
Modules string `field:"modules"` // 允许的模块
15+
CanLogin uint8 `field:"canLogin"` // 是否可以登录
1516
}
1617

1718
type AdminOperator struct {
@@ -25,6 +26,7 @@ type AdminOperator struct {
2526
UpdatedAt interface{} // 修改时间
2627
State interface{} // 状态
2728
Modules interface{} // 允许的模块
29+
CanLogin interface{} // 是否可以登录
2830
}
2931

3032
func NewAdminOperator() *AdminOperator {

internal/rpc/services/service_admin.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnab
181181
IsSuper: admin.IsSuper == 1,
182182
Modules: pbModules,
183183
OtpLogin: pbOtpAuth,
184+
CanLogin: admin.CanLogin == 1,
184185
}
185186
return &pb.FindEnabledAdminResponse{Admin: result}, nil
186187
}
@@ -206,7 +207,7 @@ func (this *AdminService) CreateOrUpdateAdmin(ctx context.Context, req *pb.Creat
206207
}
207208
return &pb.CreateOrUpdateAdminResponse{AdminId: adminId}, nil
208209
}
209-
adminId, err = models.SharedAdminDAO.CreateAdmin(tx, req.Username, req.Password, "管理员", true, nil)
210+
adminId, err = models.SharedAdminDAO.CreateAdmin(tx, req.Username, true, req.Password, "管理员", true, nil)
210211
if err != nil {
211212
return nil, err
212213
}
@@ -312,7 +313,7 @@ func (this *AdminService) CreateAdmin(ctx context.Context, req *pb.CreateAdminRe
312313

313314
tx := this.NullTx()
314315

315-
adminId, err := models.SharedAdminDAO.CreateAdmin(tx, req.Username, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON)
316+
adminId, err := models.SharedAdminDAO.CreateAdmin(tx, req.Username, req.CanLogin, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON)
316317
if err != nil {
317318
return nil, err
318319
}
@@ -331,7 +332,7 @@ func (this *AdminService) UpdateAdmin(ctx context.Context, req *pb.UpdateAdminRe
331332

332333
tx := this.NullTx()
333334

334-
err = models.SharedAdminDAO.UpdateAdmin(tx, req.AdminId, req.Username, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON, req.IsOn)
335+
err = models.SharedAdminDAO.UpdateAdmin(tx, req.AdminId, req.Username, req.CanLogin, req.Password, req.Fullname, req.IsSuper, req.ModulesJSON, req.IsOn)
335336
if err != nil {
336337
return nil, err
337338
}
@@ -399,6 +400,7 @@ func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEna
399400
IsSuper: admin.IsSuper == 1,
400401
CreatedAt: int64(admin.CreatedAt),
401402
OtpLogin: pbOtpAuth,
403+
CanLogin: admin.CanLogin == 1,
402404
})
403405
}
404406

0 commit comments

Comments
 (0)