From 219f361979cc4bef7b26c43a6f65ccf83aa55aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Tue, 30 Mar 2021 11:00:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=98=AF=E5=90=A6=E5=85=81=E8=AE=B8=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/admin_dao.go | 9 ++++++--- internal/db/models/admin_model.go | 2 ++ internal/rpc/services/service_admin.go | 8 +++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/db/models/admin_dao.go b/internal/db/models/admin_dao.go index 531b9437..bdecc3e9 100644 --- a/internal/db/models/admin_dao.go +++ b/internal/db/models/admin_dao.go @@ -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(). diff --git a/internal/db/models/admin_model.go b/internal/db/models/admin_model.go index d0dab029..73a2906c 100644 --- a/internal/db/models/admin_model.go +++ b/internal/db/models/admin_model.go @@ -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 { diff --git a/internal/rpc/services/service_admin.go b/internal/rpc/services/service_admin.go index 18676391..d808c36f 100644 --- a/internal/rpc/services/service_admin.go +++ b/internal/rpc/services/service_admin.go @@ -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, }) }