|
@@ -7,6 +7,8 @@ import ( |
|
@@ -7,6 +7,8 @@ import ( |
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
|
|
8
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
|
8
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
|
|
9
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
|
10
|
+ domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service"
|
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service"
|
|
10
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
|
12
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
|
|
11
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
|
13
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
|
|
12
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
14
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
|
@@ -129,9 +131,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode |
|
@@ -129,9 +131,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode |
|
129
|
func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) {
|
131
|
func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) {
|
|
130
|
var (
|
132
|
var (
|
|
131
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
133
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
132
|
- PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext)
|
|
|
|
133
|
- PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
|
|
|
134
|
- partnerInfo *domain.PartnerInfo
|
134
|
+ UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
|
|
135
|
)
|
135
|
)
|
|
136
|
if err = transactionContext.StartTransaction(); err != nil {
|
136
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
137
|
return nil, err
|
137
|
return nil, err
|
|
@@ -139,32 +139,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
@@ -139,32 +139,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
139
|
defer func() {
|
139
|
defer func() {
|
|
140
|
transactionContext.RollbackTransaction()
|
140
|
transactionContext.RollbackTransaction()
|
|
141
|
}()
|
141
|
}()
|
|
142
|
- // 管理员不支持修改手机号
|
|
|
|
143
|
- if header.AdminType == int(protocolx.AdminTypeManager) {
|
|
|
|
144
|
- //if err=changeUserPhone(header.UserId,request.Phone,transactionContext);err!=nil{
|
|
|
|
145
|
- // err = protocol.NewCustomMessage(1,err.Error())
|
|
|
|
146
|
- //}
|
|
|
|
147
|
- return
|
|
|
|
148
|
- }
|
|
|
|
149
|
- if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
|
150
|
- err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
|
151
|
- return
|
|
|
|
152
|
- }
|
|
|
|
153
|
- //验证新手机是否已经存在
|
|
|
|
154
|
- if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": request.Phone}); e == nil {
|
|
|
|
155
|
- err = protocol.NewErrWithMessage(2029, err) //账号已存在
|
|
|
|
156
|
- return
|
|
|
|
157
|
- }
|
|
|
|
158
|
- if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil {
|
|
|
|
159
|
- log.Error(err)
|
|
|
|
160
|
- return
|
|
|
|
161
|
- }
|
|
|
|
162
|
- if err = PartnerInfoDao.Update(map[string]interface{}{
|
|
|
|
163
|
- "Id": partnerInfo.Id,
|
|
|
|
164
|
- "Account": request.Phone,
|
|
|
|
165
|
- }); err != nil {
|
142
|
+ if err = UserAuthService.ChangeUserPhone(header.UserId, request.Phone, request.OldPhone); err != nil {
|
|
166
|
return
|
143
|
return
|
|
167
|
}
|
144
|
}
|
|
|
|
145
|
+ //TODO:修改完手机号 ,token失效,清理缓存
|
|
168
|
err = transactionContext.CommitTransaction()
|
146
|
err = transactionContext.CommitTransaction()
|
|
169
|
return
|
147
|
return
|
|
170
|
}
|
148
|
}
|
|
@@ -172,10 +150,8 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
@@ -172,10 +150,8 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
172
|
//重置密码
|
150
|
//重置密码
|
|
173
|
func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
|
151
|
func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
|
|
174
|
var (
|
152
|
var (
|
|
175
|
- partnerInfo *domain.PartnerInfo
|
|
|
|
176
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
153
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
177
|
- PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext)
|
|
|
|
178
|
- PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
154
|
+ UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
|
|
179
|
)
|
155
|
)
|
|
180
|
rsp = &protocol.ResetPasswordResponse{}
|
156
|
rsp = &protocol.ResetPasswordResponse{}
|
|
181
|
if err = transactionContext.StartTransaction(); err != nil {
|
157
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
@@ -184,40 +160,9 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo |
|
@@ -184,40 +160,9 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo |
|
184
|
defer func() {
|
160
|
defer func() {
|
|
185
|
transactionContext.RollbackTransaction()
|
161
|
transactionContext.RollbackTransaction()
|
|
186
|
}()
|
162
|
}()
|
|
187
|
- if len(request.NewPwd) < 6 {
|
|
|
|
188
|
- err = protocol.NewErrWithMessage(2027)
|
|
|
|
189
|
- return
|
|
|
|
190
|
- }
|
|
|
|
191
|
- if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
|
|
|
|
192
|
- err = protocol.NewErrWithMessage(2026)
|
|
|
|
193
|
- return
|
|
|
|
194
|
- }
|
|
|
|
195
|
- if header.AdminType == int(protocolx.AdminTypeManager) {
|
|
|
|
196
|
- if err = changeUserInfo(header.UserId, fmt.Sprintf("%v", header.SimNum), request.NewPwd, transactionContext); err != nil {
|
|
|
|
197
|
- err = protocol.NewCustomMessage(1, err.Error())
|
|
|
|
198
|
- }
|
163
|
+ if err = UserAuthService.ResetUserPassword(header.UserId, fmt.Sprintf("%v", header.SimNum), request.NewPwd); err != nil {
|
|
199
|
return
|
164
|
return
|
|
200
|
}
|
165
|
}
|
|
201
|
- if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
|
202
|
- err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
|
203
|
- return
|
|
|
|
204
|
- }
|
|
|
|
205
|
- if err = PartnerInfoDao.Update(map[string]interface{}{
|
|
|
|
206
|
- "Id": partnerInfo.Id,
|
|
|
|
207
|
- "Password": request.ConfirmPwd,
|
|
|
|
208
|
- }); err != nil {
|
|
|
|
209
|
- return
|
|
|
|
210
|
- }
|
|
|
|
211
|
- //清除auth token
|
|
|
|
212
|
- //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId))
|
|
|
|
213
|
- //if !auth.Exist() {
|
|
|
|
214
|
- // return
|
|
|
|
215
|
- //}
|
|
|
|
216
|
- //if err = auth.RemoveAuth(); err != nil {
|
|
|
|
217
|
- // log.Error(err)
|
|
|
|
218
|
- // err = protocol.NewErrWithMessage(4140, err)
|
|
|
|
219
|
- // return
|
|
|
|
220
|
- //}
|
|
|
|
221
|
err = transactionContext.CommitTransaction()
|
166
|
err = transactionContext.CommitTransaction()
|
|
222
|
return
|
167
|
return
|
|
223
|
}
|
168
|
}
|
|
@@ -225,10 +170,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo |
|
@@ -225,10 +170,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo |
|
225
|
//修改密码
|
170
|
//修改密码
|
|
226
|
func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
|
171
|
func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
|
|
227
|
var (
|
172
|
var (
|
|
228
|
- partnerInfo *domain.PartnerInfo
|
|
|
|
229
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
173
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
230
|
- PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext)
|
|
|
|
231
|
- PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
174
|
+ UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
|
|
232
|
)
|
175
|
)
|
|
233
|
if err = transactionContext.StartTransaction(); err != nil {
|
176
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
234
|
return nil, err
|
177
|
return nil, err
|
|
@@ -237,49 +180,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
@@ -237,49 +180,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
237
|
transactionContext.RollbackTransaction()
|
180
|
transactionContext.RollbackTransaction()
|
|
238
|
}()
|
181
|
}()
|
|
239
|
rsp = &protocol.ChangePasswordResponse{}
|
182
|
rsp = &protocol.ChangePasswordResponse{}
|
|
240
|
- if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
|
|
|
|
241
|
- err = protocol.NewErrWithMessage(2026)
|
183
|
+ if err = UserAuthService.ChangeUserPassword(header.UserId, request.NewPwd, request.OldPwd, fmt.Sprintf("%v", header.SimNum)); err != nil {
|
|
|
|
184
|
+ err = protocol.NewCustomMessage(1, err.Error())
|
|
242
|
return
|
185
|
return
|
|
243
|
}
|
186
|
}
|
|
244
|
- if header.AdminType == int(protocolx.AdminTypeManager) {
|
|
|
|
245
|
- if err = changeUserPassword(header.UserId, request.NewPwd, request.OldPwd, fmt.Sprintf("%v", header.SimNum), transactionContext); err != nil {
|
|
|
|
246
|
- err = protocol.NewCustomMessage(1, err.Error())
|
|
|
|
247
|
- }
|
|
|
|
248
|
- return
|
|
|
|
249
|
- }
|
|
|
|
250
|
- if strings.EqualFold(request.NewPwd, request.OldPwd) {
|
|
|
|
251
|
- err = protocol.NewErrWithMessage(2030)
|
|
|
|
252
|
- return
|
|
|
|
253
|
- }
|
|
|
|
254
|
- if len(request.NewPwd) < 6 {
|
|
|
|
255
|
- err = protocol.NewErrWithMessage(2027)
|
|
|
|
256
|
- return
|
|
|
|
257
|
- }
|
|
|
|
258
|
- if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
|
259
|
- err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
|
260
|
- return
|
|
|
|
261
|
- }
|
|
|
|
262
|
- if !strings.EqualFold(partnerInfo.Password, request.OldPwd) {
|
|
|
|
263
|
- //密码不一致
|
|
|
|
264
|
- err = protocol.NewErrWithMessage(2028, err) //账号不存在
|
|
|
|
265
|
- return
|
|
|
|
266
|
- }
|
|
|
|
267
|
- if err = PartnerInfoDao.Update(map[string]interface{}{
|
|
|
|
268
|
- "Id": partnerInfo.Id,
|
|
|
|
269
|
- "Password": request.ConfirmPwd,
|
|
|
|
270
|
- }); err != nil {
|
|
|
|
271
|
- return
|
|
|
|
272
|
- }
|
|
|
|
273
|
- //清除auth token
|
|
|
|
274
|
- //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId))
|
|
|
|
275
|
- //if !auth.Exist() {
|
|
|
|
276
|
- // return
|
|
|
|
277
|
- //}
|
|
|
|
278
|
- //if err = auth.RemoveAuth(); err != nil {
|
|
|
|
279
|
- // log.Error(err)
|
|
|
|
280
|
- // err = protocol.NewErrWithMessage(4140, err)
|
|
|
|
281
|
- // return
|
|
|
|
282
|
- //}
|
|
|
|
283
|
err = transactionContext.CommitTransaction()
|
187
|
err = transactionContext.CommitTransaction()
|
|
284
|
return
|
188
|
return
|
|
285
|
}
|
189
|
}
|
|
@@ -401,10 +305,10 @@ func changeUserInfo(userId int64, phone, password string, transactionContext *tr |
|
@@ -401,10 +305,10 @@ func changeUserInfo(userId int64, phone, password string, transactionContext *tr |
|
401
|
err = fmt.Errorf("用户不存在")
|
305
|
err = fmt.Errorf("用户不存在")
|
|
402
|
return
|
306
|
return
|
|
403
|
}
|
307
|
}
|
|
404
|
- _, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, password)
|
308
|
+ _, err = ucenterApiGateway.UpdateUser(user.OpenId, phone, password)
|
|
405
|
return
|
309
|
return
|
|
406
|
}
|
310
|
}
|
|
407
|
-func changeUserPhone(userId int64, phone string, transactionContext *transaction.TransactionContext) (err error) {
|
311
|
+func changeUserPhone(userId int64, phone, oldPhone string, transactionContext *transaction.TransactionContext) (err error) {
|
|
408
|
var (
|
312
|
var (
|
|
409
|
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
|
313
|
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
|
|
410
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
314
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
|
@@ -419,10 +323,10 @@ func changeUserPhone(userId int64, phone string, transactionContext *transaction |
|
@@ -419,10 +323,10 @@ func changeUserPhone(userId int64, phone string, transactionContext *transaction |
|
419
|
err = protocol.NewErrWithMessage(2029, err)
|
323
|
err = protocol.NewErrWithMessage(2029, err)
|
|
420
|
return
|
324
|
return
|
|
421
|
}
|
325
|
}
|
|
422
|
- _, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, "")
|
|
|
|
423
|
- if err != nil {
|
|
|
|
424
|
- _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId)
|
|
|
|
425
|
- }
|
326
|
+ _, err = ucenterApiGateway.ChangePhone(phone, oldPhone)
|
|
|
|
327
|
+ //if err != nil {
|
|
|
|
328
|
+ // _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId)
|
|
|
|
329
|
+ //}
|
|
426
|
return
|
330
|
return
|
|
427
|
}
|
331
|
}
|
|
428
|
func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) {
|
332
|
func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) {
|
|
@@ -439,3 +343,22 @@ func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionC |
|
@@ -439,3 +343,22 @@ func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionC |
|
439
|
_, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd)
|
343
|
_, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd)
|
|
440
|
return
|
344
|
return
|
|
441
|
}
|
345
|
}
|
|
|
|
346
|
+
|
|
|
|
347
|
+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)
|
|
|
|
352
|
+}
|
|
|
|
353
|
+
|
|
|
|
354
|
+//TODO:修改密码/重置密码 清除uer_auth 缓存
|
|
|
|
355
|
+//清除auth token
|
|
|
|
356
|
+//auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId))
|
|
|
|
357
|
+//if !auth.Exist() {
|
|
|
|
358
|
+// return
|
|
|
|
359
|
+//}
|
|
|
|
360
|
+//if err = auth.RemoveAuth(); err != nil {
|
|
|
|
361
|
+// log.Error(err)
|
|
|
|
362
|
+// err = protocol.NewErrWithMessage(4140, err)
|
|
|
|
363
|
+// return
|
|
|
|
364
|
+//} |