作者 yangfu

修改: 用户密码变更 /手机号变更

... ... @@ -10,7 +10,6 @@ import (
domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
... ... @@ -294,61 +293,14 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
return
}
func changeUserInfo(userId int64, phone, password string, transactionContext *transaction.TransactionContext) (err error) {
var (
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
user *domain.Users
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
log.Error(err)
err = fmt.Errorf("用户不存在")
return
}
_, err = ucenterApiGateway.UpdateUser(user.OpenId, phone, password)
return
}
func changeUserPhone(userId int64, phone, oldPhone string, transactionContext *transaction.TransactionContext) (err error) {
var (
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
user *domain.Users
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
log.Error(err)
err = fmt.Errorf("用户不存在")
return
}
if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": phone}); e == nil || newUser != nil {
err = protocol.NewErrWithMessage(2029, err)
return
}
_, err = ucenterApiGateway.ChangePhone(phone, oldPhone)
//if err != nil {
// _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId)
//}
return
}
func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) {
var (
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
user *domain.Users
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
log.Error(err)
err = fmt.Errorf("用户不存在")
return
}
_, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd)
return
}
func CreateUserAuthService(adminType int, transactionContext *transaction.TransactionContext) domain_service_i.UserAuthService {
if adminType == int(protocolx.AdminTypeManager) {
return domain_service.NewPgManagerAuthService(transactionContext)
}
return domain_service.NewPgPartnerAuthService(transactionContext)
//if adminType==0{
return domain_service.NewPgAuthService(transactionContext)
//}
//if adminType == int(protocolx.AdminTypeManager) {
// return domain_service.NewPgManagerAuthService(transactionContext)
//}
//return domain_service.NewPgPartnerAuthService(transactionContext)
}
//TODO:修改密码/重置密码 清除uer_auth 缓存
... ...
... ... @@ -2,11 +2,11 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "partner_test" //partner
var POSTGRESQL_USER = "postgres" //
var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123
var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1
var POSTGRESQL_PORT = "31543" //5432
var POSTGRESQL_DB_NAME = "partner_dev" //partner
var POSTGRESQL_USER = "postgres" //
var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123
var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1
var POSTGRESQL_PORT = "31543" //5432
var DISABLE_CREATE_TABLE = false
var DISABLE_SQL_GENERATE_PRINT = false
... ...
... ... @@ -24,7 +24,9 @@ func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error {
query.SetWhere(`id=?`, "Id")
query.SetWhere(`account=?`, "oldAccount")
if _, ok := queryOptions["Id"]; !ok {
return fmt.Errorf(`error: miss param "Id"`)
if _, ok := queryOptions["oldAccount"]; !ok {
return fmt.Errorf(`error: miss param "Id"`)
}
}
_, err := query.Update()
return err
... ...
package domain_service
import (
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
)
type PgAuthService struct {
eda.EventCenterPublisher
//transactionContext *transaction.TransactionContext
manager *PgManagerAuthService
partner *PgPartnerAuthService
}
func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
return &PgAuthService{
manager: NewPgManagerAuthService(ctx),
partner: NewPgPartnerAuthService(ctx),
}
}
func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone)
errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone)
if errPartner != nil && errManager != nil {
log.Error("partner:", errPartner, "mannager:", errManager)
err = errPartner
return
}
return
}
func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone)
errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone)
if errPartner != nil && errManager != nil {
log.Error(errPartner, errManager)
err = errPartner
return
}
return
}
func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) {
errPartner := s.partner.ResetUserPassword(userId, phone, password)
errManager := s.manager.ResetUserPassword(userId, phone, password)
if errPartner != nil && errManager != nil {
log.Error(errPartner, errManager)
err = errPartner
return
}
return
}
... ...
... ... @@ -11,6 +11,8 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
)
var errUserNotFound = fmt.Errorf("用户不存在")
type PgManagerAuthService struct {
eda.EventCenterPublisher
transactionContext *transaction.TransactionContext
... ... @@ -28,9 +30,9 @@ func (s *PgManagerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone
UsersRepository, _ = repository.NewUsersRepository(s.transactionContext)
user *domain.Users
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
if user, err = UsersRepository.FindOne(map[string]interface{}{"phone": oldPhone}); err != nil || user == nil {
log.Error(err)
err = fmt.Errorf("用户不存在")
err = errUserNotFound
return
}
if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": newPhone}); e == nil || newUser != nil {
... ... @@ -50,7 +52,7 @@ func (s *PgManagerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd,
UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext)
user *domain.Users
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
if user, err = UsersRepository.FindOne(map[string]interface{}{"phone": phone}); err != nil || user == nil {
log.Error(err)
err = fmt.Errorf("用户不存在")
return
... ... @@ -64,7 +66,7 @@ func (s *PgManagerAuthService) ResetUserPassword(userId int64, phone, password s
UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext)
user *domain.Users
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
if user, err = UsersRepository.FindOne(map[string]interface{}{"phone": phone}); err != nil || user == nil {
log.Error(err)
err = fmt.Errorf("用户不存在")
return
... ...
... ... @@ -29,11 +29,11 @@ func (s *PgPartnerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone
)
//验证新手机是否已经存在
if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": newPhone}); e == nil {
err = fmt.Errorf("账号已存在") //账号已存在
err = fmt.Errorf("当前手机号已存在,请重新输入") //账号已存在
return
}
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil || (partnerInfo.Account != oldPhone) {
err = fmt.Errorf("账号不存在") //账号不存在
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": oldPhone}); err != nil || (partnerInfo.Account != oldPhone) {
err = errUserNotFound //账号不存在
return
}
if err = PartnerInfoDao.Update(map[string]interface{}{
... ... @@ -50,13 +50,12 @@ func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd,
PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext)
PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext)
)
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil {
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": phone}); err != nil {
err = fmt.Errorf("账号不存在") //账号不存在
return
}
if !strings.EqualFold(partnerInfo.Password, oldPwd) {
//密码不一致
err = fmt.Errorf("账号不存在") //账号不存在
err = fmt.Errorf("旧密码不正确") //账号不存在
return
}
if err = PartnerInfoDao.Update(map[string]interface{}{
... ...
... ... @@ -21,7 +21,10 @@ func CheckJWTToken(ctx *context.Context) {
strings.HasSuffix(ctx.Request.RequestURI, "smsCode") ||
strings.HasSuffix(ctx.Request.RequestURI, "centerCompanys") ||
strings.HasSuffix(ctx.Request.RequestURI, "companys") ||
strings.HasSuffix(ctx.Request.RequestURI, "loginV2") {
strings.HasSuffix(ctx.Request.RequestURI, "loginV2") ||
strings.HasSuffix(ctx.Request.RequestURI, "changePhone") ||
strings.HasSuffix(ctx.Request.RequestURI, "resetPassword") ||
strings.HasSuffix(ctx.Request.RequestURI, "changePassword") {
return
}
defer func() {
... ...