email_prepare.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 githup.com. All rights reserved.
  2. // Use of this source code is governed by githup.com.
  3. package user
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "github.com/jaryhe/gopkgs/logger"
  8. "github.com/jinzhu/gorm"
  9. "go.uber.org/zap"
  10. "smart-enterprise-management/errors"
  11. dbmodel "smart-enterprise-management/model"
  12. pb_v1 "smart-enterprise-management/pb/v1"
  13. )
  14. func EmailPrepare(ctx context.Context, req *pb_v1.EmailPrepareRequest)(reply *pb_v1.EmailPrepareReply, err error) {
  15. p := &dbmodel.TCompany{}
  16. if req.Password == "" || req.Email == "" {
  17. return nil, errors.ParamsError
  18. }
  19. where := map[string]interface{}{
  20. "id":req.Id,
  21. }
  22. // 状态判断
  23. err = p.Find(database.DB(), where, nil)
  24. if err != nil && err != gorm.ErrRecordNotFound{
  25. logger.Error("EmailPrepare",
  26. zap.String("err", err.Error()))
  27. return nil, errors.DataBaseError
  28. }
  29. if p.Id == 0 {
  30. return nil, errors.NoRecordError
  31. }
  32. pass, _ := getMd5Pass(req.Password)
  33. if p.Passwd != pass {
  34. return nil, errors.UserPassError
  35. }
  36. p = &dbmodel.TCompany{}
  37. where = map[string]interface{}{
  38. "email":req.Email,
  39. }
  40. // 状态判断
  41. err = p.Find(database.DB(), where, nil)
  42. if err != nil && err != gorm.ErrRecordNotFound{
  43. logger.Error("EmailPrepare",
  44. zap.String("err", err.Error()))
  45. return nil, errors.DataBaseError
  46. }
  47. if p.Id > 0 {
  48. return nil, errors.EmailExist
  49. }
  50. reply = &pb_v1.EmailPrepareReply{}
  51. return reply, nil
  52. }