pull/148/head
wangchuxiao 3 years ago
parent 75590eb765
commit 55d7c6e672

@ -60,9 +60,9 @@ func SendVerificationCode(c *gin.Context) {
case constant.VerificationCodeForReset:
accountKey = account + "_" + constant.VerificationCodeForResetSuffix
}
log.NewInfo(params.OperationID, params.UsedFor,"begin store redis", accountKey)
rand.Seed(time.Now().UnixNano())
code := 100000 + rand.Intn(900000)
log.NewInfo(params.OperationID, params.UsedFor,"begin store redis", accountKey, code)
err := db.DB.SetAccountCode(accountKey, code, config.Config.Demo.CodeTTL)
if err != nil {
log.NewError(params.OperationID, "set redis error", accountKey, "err", err.Error())

@ -778,10 +778,26 @@ func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.OperateUserRoleResp{}
if err := imdb.OperateGroupRole(req.UserId, req.GroupId, req.RoleLevel); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "OperateGroupRole error", err.Error())
oldOwnerUserID, err := imdb.GetGroupMaster(req.GroupId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pbGroup.NewGroupClient(etcdConn)
var reqPb pbGroup.TransferGroupOwnerReq
reqPb.OperationID = req.OperationID
reqPb.NewOwnerUserID = req.UserId
reqPb.GroupID = req.GroupId
reqPb.OpUserID = "cms admin"
reqPb.OldOwnerUserID = oldOwnerUserID.UserID
reply, err := client.TransferGroupOwner(context.Background(), &reqPb)
if reply.CommonResp.ErrCode != 0 || err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "TransferGroupOwner rpc failed")
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
}
return resp, nil
}

@ -116,10 +116,10 @@ func DeleteGroup(groupId string) error {
return nil
}
func OperateGroupRole(userId, groupId string, roleLevel int32) error {
func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
return "", "", err
}
dbConn.LogMode(true)
groupMember := db.GroupMember{
@ -133,7 +133,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
}
switch roleLevel {
case constant.GroupOwner:
return dbConn.Transaction(func(tx *gorm.DB) error {
err = dbConn.Transaction(func(tx *gorm.DB) error {
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{
RoleLevel: constant.GroupOrdinaryUsers,
})
@ -153,14 +153,15 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
}
return nil
})
case constant.GroupOrdinaryUsers:
return dbConn.Transaction(func(tx *gorm.DB) error {
err = dbConn.Transaction(func(tx *gorm.DB) error {
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
if groupMaster.UserID == userId {
return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId))
@ -170,13 +171,13 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
return result.Error
}
if result.RowsAffected == 0 {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
}
return nil
})
}
return nil
return "", "", nil
}
func GetGroupsCountNum(group db.Group) (int32, error) {

Loading…
Cancel
Save