123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // 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-site-management/errors"
- dbmodel "smart-site-management/model"
- pb_v1 "smart-site-management/pb/v1"
- )
- func EmailPrepare(ctx context.Context, req *pb_v1.EmailPrepareRequest)(reply *pb_v1.EmailPrepareReply, err error) {
- p := &dbmodel.TSiteUser{}
- 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 {
- logger.Error("EmailPrepare",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return nil, errors.NoRecordError
- }
- pass, _ := getB64Pass(req.Password)
- if p.Passwd != pass {
- return nil, errors.UserPassError
- }
- p = &dbmodel.TSiteUser{}
- 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
- }
|