pg_partner_auth_services.go
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package domain_service
import (
"fmt"
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/repository"
"strings"
)
type PgPartnerAuthService struct {
eda.EventCenterPublisher
transactionContext *transaction.TransactionContext
}
func NewPgPartnerAuthService(ctx *transaction.TransactionContext) *PgPartnerAuthService {
return &PgPartnerAuthService{
transactionContext: ctx,
}
}
func (s *PgPartnerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
var (
PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext)
PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext)
partnerInfo *domain.PartnerInfo
)
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": oldPhone}); err != nil || (partnerInfo.Account != oldPhone) {
err = errUserNotFound //账号不存在
return
}
//验证新手机是否已经存在
if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": newPhone}); e == nil {
err = fmt.Errorf("当前手机号已存在,请重新输入") //账号已存在
return
}
if err = PartnerInfoDao.Update(map[string]interface{}{
"oldAccount": oldPhone,
"Account": newPhone,
}); err != nil {
return
}
return
}
/**
* @Author SteveChan
* @Description 密码校验增加多公司
* @Date 11:52 2021/2/7
* @Param
* @return
**/
func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
var (
//partnerInfo *domain.PartnerInfo
partnerInfos []*domain.PartnerInfo
PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext)
PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext)
)
// 查询账号信息
if _, partnerInfos, err = PartnerInfoService.Find(map[string]interface{}{"account": phone}); err != nil {
err = errUserNotFound //账号不存在
return
}
//多公司密码校验
var misMatch bool
for _, partnerInfo := range partnerInfos {
if !strings.EqualFold(partnerInfo.Password, oldPwd) {
misMatch = true
} else {
misMatch = false
break
}
}
if misMatch {
err = fmt.Errorf("旧密码不正确") //账号不存在
return
}
//if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": phone}); err != nil {
// err = errUserNotFound //账号不存在
// return
//}
//if !strings.EqualFold(partnerInfo.Password, oldPwd) {
// err = fmt.Errorf("旧密码不正确") //账号不存在
// return
//}
if err = PartnerInfoDao.Update(map[string]interface{}{
"oldAccount": phone,
"Password": newPwd,
}); err != nil {
return
}
return
}
func (s *PgPartnerAuthService) ResetUserPassword(userId int64, phone, password string) (err error) {
var (
//partnerInfo *domain.PartnerInfo
PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext)
PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext)
)
if _, err = PartnerInfoService.FindOne(map[string]interface{}{"account": phone}); err != nil {
err = errUserNotFound //账号不存在
return
}
if err = PartnerInfoDao.Update(map[string]interface{}{
"oldAccount": phone,
"Password": password,
}); err != nil {
return
}
return
}