super_user_reset_password.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package organization
  4. import (
  5. "context"
  6. "cp-system-management/errors"
  7. "cp-system-management/pb"
  8. pb_v1 "cp-system-management/pb/v1"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/jaryhe/gopkgs/logger"
  12. "go.uber.org/zap"
  13. "google.golang.org/grpc/status"
  14. )
  15. //
  16. func OrganizationUserResetPassword(ctx context.Context, req *pb_v1.OrganizationUserResetPasswordRequest) (reply *pb_v1.OrganizationUserResetPasswordReply, err error) {
  17. reply = &pb_v1.OrganizationUserResetPasswordReply{}
  18. // 捕获各个task中的异常并返回给调用者
  19. defer func() {
  20. if r := recover(); r != nil {
  21. err = fmt.Errorf("%+v", r)
  22. e := &status.Status{}
  23. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  24. logger.Error("err",
  25. zap.String("system_err", err.Error()),
  26. zap.Stack("stacktrace"))
  27. }
  28. }
  29. }()
  30. if req.Id == 0 || req.OrganizationCode == "" || req.Password == "" {
  31. return nil, errors.ParamsError
  32. }
  33. rReq := &pb_v1.ManagementSuperUserResetPasswordRequest{
  34. OrganizationCode: req.OrganizationCode,
  35. Id:req.Id,
  36. Password:req.Password,
  37. }
  38. _, err = pb.Organization.ManagementSuperUserResetPassword(ctx, rReq)
  39. if err != nil {
  40. return reply, errors.ServiceError
  41. }
  42. return reply, nil
  43. }