作者 yangfu

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

@@ -10,7 +10,6 @@ import ( @@ -10,7 +10,6 @@ import (
10 domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service" 10 domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service"
11 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service" 11 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service"
12 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" 12 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
13 - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"  
14 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 13 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
15 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 14 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
16 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth" 15 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
@@ -294,61 +293,14 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -294,61 +293,14 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
294 return 293 return
295 } 294 }
296 295
297 -func changeUserInfo(userId int64, phone, password string, transactionContext *transaction.TransactionContext) (err error) {  
298 - var (  
299 - ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()  
300 - UsersRepository, _ = factory.CreateUsersRepository(transactionContext)  
301 - user *domain.Users  
302 - )  
303 - if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {  
304 - log.Error(err)  
305 - err = fmt.Errorf("用户不存在")  
306 - return  
307 - }  
308 - _, err = ucenterApiGateway.UpdateUser(user.OpenId, phone, password)  
309 - return  
310 -}  
311 -func changeUserPhone(userId int64, phone, oldPhone string, transactionContext *transaction.TransactionContext) (err error) {  
312 - var (  
313 - ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()  
314 - UsersRepository, _ = factory.CreateUsersRepository(transactionContext)  
315 - user *domain.Users  
316 - )  
317 - if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {  
318 - log.Error(err)  
319 - err = fmt.Errorf("用户不存在")  
320 - return  
321 - }  
322 - if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": phone}); e == nil || newUser != nil {  
323 - err = protocol.NewErrWithMessage(2029, err)  
324 - return  
325 - }  
326 - _, err = ucenterApiGateway.ChangePhone(phone, oldPhone)  
327 - //if err != nil {  
328 - // _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId)  
329 - //}  
330 - return  
331 -}  
332 -func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) {  
333 - var (  
334 - ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()  
335 - UsersRepository, _ = factory.CreateUsersRepository(transactionContext)  
336 - user *domain.Users  
337 - )  
338 - if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {  
339 - log.Error(err)  
340 - err = fmt.Errorf("用户不存在")  
341 - return  
342 - }  
343 - _, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd)  
344 - return  
345 -}  
346 -  
347 func CreateUserAuthService(adminType int, transactionContext *transaction.TransactionContext) domain_service_i.UserAuthService { 296 func CreateUserAuthService(adminType int, transactionContext *transaction.TransactionContext) domain_service_i.UserAuthService {
348 - if adminType == int(protocolx.AdminTypeManager) {  
349 - return domain_service.NewPgManagerAuthService(transactionContext)  
350 - }  
351 - return domain_service.NewPgPartnerAuthService(transactionContext) 297 + //if adminType==0{
  298 + return domain_service.NewPgAuthService(transactionContext)
  299 + //}
  300 + //if adminType == int(protocolx.AdminTypeManager) {
  301 + // return domain_service.NewPgManagerAuthService(transactionContext)
  302 + //}
  303 + //return domain_service.NewPgPartnerAuthService(transactionContext)
352 } 304 }
353 305
354 //TODO:修改密码/重置密码 清除uer_auth 缓存 306 //TODO:修改密码/重置密码 清除uer_auth 缓存
@@ -2,11 +2,11 @@ package constant @@ -2,11 +2,11 @@ package constant
2 2
3 import "os" 3 import "os"
4 4
5 -var POSTGRESQL_DB_NAME = "partner_test" //partner  
6 -var POSTGRESQL_USER = "postgres" //  
7 -var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123  
8 -var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1  
9 -var POSTGRESQL_PORT = "31543" //5432 5 +var POSTGRESQL_DB_NAME = "partner_dev" //partner
  6 +var POSTGRESQL_USER = "postgres" //
  7 +var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123
  8 +var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1
  9 +var POSTGRESQL_PORT = "31543" //5432
10 var DISABLE_CREATE_TABLE = false 10 var DISABLE_CREATE_TABLE = false
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
@@ -24,7 +24,9 @@ func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error { @@ -24,7 +24,9 @@ func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error {
24 query.SetWhere(`id=?`, "Id") 24 query.SetWhere(`id=?`, "Id")
25 query.SetWhere(`account=?`, "oldAccount") 25 query.SetWhere(`account=?`, "oldAccount")
26 if _, ok := queryOptions["Id"]; !ok { 26 if _, ok := queryOptions["Id"]; !ok {
27 - return fmt.Errorf(`error: miss param "Id"`) 27 + if _, ok := queryOptions["oldAccount"]; !ok {
  28 + return fmt.Errorf(`error: miss param "Id"`)
  29 + }
28 } 30 }
29 _, err := query.Update() 31 _, err := query.Update()
30 return err 32 return err
  1 +package domain_service
  2 +
  3 +import (
  4 + "github.com/tiptok/gocomm/xa/eda"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
  7 +)
  8 +
  9 +type PgAuthService struct {
  10 + eda.EventCenterPublisher
  11 + //transactionContext *transaction.TransactionContext
  12 + manager *PgManagerAuthService
  13 + partner *PgPartnerAuthService
  14 +}
  15 +
  16 +func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
  17 + return &PgAuthService{
  18 + manager: NewPgManagerAuthService(ctx),
  19 + partner: NewPgPartnerAuthService(ctx),
  20 + }
  21 +}
  22 +
  23 +func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
  24 + errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone)
  25 + errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone)
  26 + if errPartner != nil && errManager != nil {
  27 + log.Error("partner:", errPartner, "mannager:", errManager)
  28 + err = errPartner
  29 + return
  30 + }
  31 + return
  32 +}
  33 +func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
  34 + errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone)
  35 + errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone)
  36 + if errPartner != nil && errManager != nil {
  37 + log.Error(errPartner, errManager)
  38 + err = errPartner
  39 + return
  40 + }
  41 + return
  42 +}
  43 +func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) {
  44 + errPartner := s.partner.ResetUserPassword(userId, phone, password)
  45 + errManager := s.manager.ResetUserPassword(userId, phone, password)
  46 + if errPartner != nil && errManager != nil {
  47 + log.Error(errPartner, errManager)
  48 + err = errPartner
  49 + return
  50 + }
  51 + return
  52 +}
@@ -11,6 +11,8 @@ import ( @@ -11,6 +11,8 @@ import (
11 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 11 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
12 ) 12 )
13 13
  14 +var errUserNotFound = fmt.Errorf("用户不存在")
  15 +
14 type PgManagerAuthService struct { 16 type PgManagerAuthService struct {
15 eda.EventCenterPublisher 17 eda.EventCenterPublisher
16 transactionContext *transaction.TransactionContext 18 transactionContext *transaction.TransactionContext
@@ -28,9 +30,9 @@ func (s *PgManagerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone @@ -28,9 +30,9 @@ func (s *PgManagerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone
28 UsersRepository, _ = repository.NewUsersRepository(s.transactionContext) 30 UsersRepository, _ = repository.NewUsersRepository(s.transactionContext)
29 user *domain.Users 31 user *domain.Users
30 ) 32 )
31 - if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil { 33 + if user, err = UsersRepository.FindOne(map[string]interface{}{"phone": oldPhone}); err != nil || user == nil {
32 log.Error(err) 34 log.Error(err)
33 - err = fmt.Errorf("用户不存在") 35 + err = errUserNotFound
34 return 36 return
35 } 37 }
36 if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": newPhone}); e == nil || newUser != nil { 38 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, @@ -50,7 +52,7 @@ func (s *PgManagerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd,
50 UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext) 52 UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext)
51 user *domain.Users 53 user *domain.Users
52 ) 54 )
53 - if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil { 55 + if user, err = UsersRepository.FindOne(map[string]interface{}{"phone": phone}); err != nil || user == nil {
54 log.Error(err) 56 log.Error(err)
55 err = fmt.Errorf("用户不存在") 57 err = fmt.Errorf("用户不存在")
56 return 58 return
@@ -64,7 +66,7 @@ func (s *PgManagerAuthService) ResetUserPassword(userId int64, phone, password s @@ -64,7 +66,7 @@ func (s *PgManagerAuthService) ResetUserPassword(userId int64, phone, password s
64 UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext) 66 UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext)
65 user *domain.Users 67 user *domain.Users
66 ) 68 )
67 - if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil { 69 + if user, err = UsersRepository.FindOne(map[string]interface{}{"phone": phone}); err != nil || user == nil {
68 log.Error(err) 70 log.Error(err)
69 err = fmt.Errorf("用户不存在") 71 err = fmt.Errorf("用户不存在")
70 return 72 return
@@ -29,11 +29,11 @@ func (s *PgPartnerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone @@ -29,11 +29,11 @@ func (s *PgPartnerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone
29 ) 29 )
30 //验证新手机是否已经存在 30 //验证新手机是否已经存在
31 if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": newPhone}); e == nil { 31 if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": newPhone}); e == nil {
32 - err = fmt.Errorf("账号已存在") //账号已存在 32 + err = fmt.Errorf("当前手机号已存在,请重新输入") //账号已存在
33 return 33 return
34 } 34 }
35 - if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil || (partnerInfo.Account != oldPhone) {  
36 - err = fmt.Errorf("账号不存在") //账号不存在 35 + if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": oldPhone}); err != nil || (partnerInfo.Account != oldPhone) {
  36 + err = errUserNotFound //账号不存在
37 return 37 return
38 } 38 }
39 if err = PartnerInfoDao.Update(map[string]interface{}{ 39 if err = PartnerInfoDao.Update(map[string]interface{}{
@@ -50,13 +50,12 @@ func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, @@ -50,13 +50,12 @@ func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd,
50 PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext) 50 PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext)
51 PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext) 51 PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext)
52 ) 52 )
53 - if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil { 53 + if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": phone}); err != nil {
54 err = fmt.Errorf("账号不存在") //账号不存在 54 err = fmt.Errorf("账号不存在") //账号不存在
55 return 55 return
56 } 56 }
57 if !strings.EqualFold(partnerInfo.Password, oldPwd) { 57 if !strings.EqualFold(partnerInfo.Password, oldPwd) {
58 - //密码不一致  
59 - err = fmt.Errorf("账号不存在") //账号不存在 58 + err = fmt.Errorf("旧密码不正确") //账号不存在
60 return 59 return
61 } 60 }
62 if err = PartnerInfoDao.Update(map[string]interface{}{ 61 if err = PartnerInfoDao.Update(map[string]interface{}{
@@ -21,7 +21,10 @@ func CheckJWTToken(ctx *context.Context) { @@ -21,7 +21,10 @@ func CheckJWTToken(ctx *context.Context) {
21 strings.HasSuffix(ctx.Request.RequestURI, "smsCode") || 21 strings.HasSuffix(ctx.Request.RequestURI, "smsCode") ||
22 strings.HasSuffix(ctx.Request.RequestURI, "centerCompanys") || 22 strings.HasSuffix(ctx.Request.RequestURI, "centerCompanys") ||
23 strings.HasSuffix(ctx.Request.RequestURI, "companys") || 23 strings.HasSuffix(ctx.Request.RequestURI, "companys") ||
24 - strings.HasSuffix(ctx.Request.RequestURI, "loginV2") { 24 + strings.HasSuffix(ctx.Request.RequestURI, "loginV2") ||
  25 + strings.HasSuffix(ctx.Request.RequestURI, "changePhone") ||
  26 + strings.HasSuffix(ctx.Request.RequestURI, "resetPassword") ||
  27 + strings.HasSuffix(ctx.Request.RequestURI, "changePassword") {
25 return 28 return
26 } 29 }
27 defer func() { 30 defer func() {