1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // Copyright 2019 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package user
- import (
- "context"
- "cp-organization-management/errors"
- "cp-organization-management/model"
- pb_v1 "cp-organization-management/pb/v1"
- "cp-organization-management/utils"
- "encoding/json"
- "fmt"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "github.com/jaryhe/gopkgs/util"
- "cp-organization-management/consts"
- )
- func ManagementSuperUserResetPassword(ctx context.Context, req *pb_v1.ManagementSuperUserResetPasswordRequest) (reply *pb_v1.ManagementSuperUserResetPasswordReply, err error) {
- reply = &pb_v1.ManagementSuperUserResetPasswordReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- if req.OrganizationCode == "" || req.Password == "" || req.Id == 0{
- return reply, status.Error(10003, "参数错误")
- }
- dbname := utils.GetDbName(req.OrganizationCode)
- p := model.NewRbacUser(dbname)
- where := map[string]interface{}{
- "id":req.Id,
- }
- passwd, _ := util.GetMd5Pass(req.Password, consts.CRYPTO_KEY)
- values := map[string]interface{}{
- "password":passwd,
- }
- rows, err := p.UpdateWithAffectRows(database.DB(), where, values)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if rows == 0 {
- return nil, errors.ErrRecordNotFound
- }
- return reply, nil
- }
|