1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package user
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- "smart-enterprise-management/errors"
- dbmodel "smart-enterprise-management/model"
- pb_v1 "smart-enterprise-management/pb/v1"
- )
- func EmailPrepare(ctx context.Context, req *pb_v1.EmailPrepareRequest)(reply *pb_v1.EmailPrepareReply, err error) {
- p := &dbmodel.TCompany{}
- if req.Password == "" || req.Email == "" {
- return nil, errors.ParamsError
- }
- where := map[string]interface{}{
- "id":req.Id,
- }
- // 状态判断
- err = p.Find(database.DB(), where, nil)
- if err != nil && err != gorm.ErrRecordNotFound{
- logger.Error("EmailPrepare",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return nil, errors.NoRecordError
- }
- pass, _ := getMd5Pass(req.Password)
- if p.Passwd != pass {
- return nil, errors.UserPassError
- }
- p = &dbmodel.TCompany{}
- where = map[string]interface{}{
- "email":req.Email,
- }
- // 状态判断
- err = p.Find(database.DB(), where, nil)
- if err != nil && err != gorm.ErrRecordNotFound{
- logger.Error("EmailPrepare",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id > 0 {
- return nil, errors.EmailExist
- }
- reply = &pb_v1.EmailPrepareReply{}
- return reply, nil
- }
|