12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package user
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jinzhu/gorm"
- "smart-enterprise-management/errors"
- dbmodel "smart-enterprise-management/model"
- "smart-enterprise-management/pb/v1"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- )
- func ChangePasswd(ctx context.Context, req *v1.ChangePasswdRequest) (reply *v1.ChangePasswdReply, err error) {
- p := &dbmodel.TCompany{}
- and := map[string]interface{}{
- "id": req.Uid,
- }
- err = p.Find(database.DB(), and, nil)
- if err != nil && err != gorm.ErrRecordNotFound {
- logger.Error("ChangePasswd",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return nil, errors.UserNotExistError
- }
- old, err := getMd5Pass(req.Old)
- if err != nil {
- logger.Error("ChangePasswd",
- zap.String("err", err.Error()))
- return nil, errors.SystemError
- }
- if p.Passwd != old {
- return nil, errors.UserPassError
- }
- where := map[string]interface{}{
- "id": req.Uid,
- }
- p.Passwd, err = getMd5Pass(req.New)
- if err != nil {
- logger.Error("ChangePasswd",
- zap.String("err", err.Error()))
- return nil, errors.SystemError
- }
- err = p.Update(database.DB(), where, map[string]interface{}{"passwd": p.Passwd})
- if err != nil {
- logger.Error("ChangePasswd",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- return &v1.ChangePasswdReply{}, nil
- }
|