package user import ( "context" "github.com/jaryhe/gopkgs/database" "github.com/jaryhe/gopkgs/logger" "go.uber.org/zap" "smart-site-management/errors" dbmodel "smart-site-management/model" "smart-site-management/pb/v1" ) func ChangePasswd(ctx context.Context, req *v1.ChangePasswdRequest) (reply *v1.ChangePasswdReply, err error) { p := &dbmodel.TSiteUser{} and := map[string]interface{}{ "id": req.Uid, } err = p.Find(database.DB(), and, nil) if err != nil { logger.Error("ChangePasswd", zap.String("err", err.Error())) return nil, errors.DataBaseError } if p.Id == 0 { return nil, errors.UserNotExistError } old, err := getB64Pass(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 = getB64Pass(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 }