|
@@ -237,10 +237,250 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
|
@@ -237,10 +237,250 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
237
|
if err != nil {
|
237
|
if err != nil {
|
238
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "refreshToken 不可用,"+err.Error())
|
238
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "refreshToken 不可用,"+err.Error())
|
239
|
}
|
239
|
}
|
240
|
- phone := ltoken.Account
|
240
|
+ token, err := srv.getToken(domain.Operator{}, ltoken)
|
|
|
241
|
+ // phone := ltoken.Account
|
|
|
242
|
+ // creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
243
|
+ // userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
244
|
+ // Phone: phone,
|
|
|
245
|
+ // })
|
|
|
246
|
+ // if err != nil {
|
|
|
247
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, "用户信息获取失败,"+err.Error())
|
|
|
248
|
+ // }
|
|
|
249
|
+ // //判定当前凭证的companyId,OrganizationId 是否在用户列表中
|
|
|
250
|
+ // var currentOrgIsOK bool
|
|
|
251
|
+ //loopUser1:
|
|
|
252
|
+ // for _, v := range userSearchResult.Users {
|
|
|
253
|
+ // if v.Company.CompanyId == int(ltoken.CompanyId) {
|
|
|
254
|
+ // for _, vv := range v.UserOrg {
|
|
|
255
|
+ // if vv.OrgID == int(ltoken.OrgId) {
|
|
|
256
|
+ // currentOrgIsOK = true
|
|
|
257
|
+ // break loopUser1
|
|
|
258
|
+ // }
|
|
|
259
|
+ // }
|
|
|
260
|
+ // }
|
|
|
261
|
+ // }
|
|
|
262
|
+ // if !currentOrgIsOK {
|
|
|
263
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
|
|
264
|
+ // }
|
|
|
265
|
+ //
|
|
|
266
|
+ // transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
267
|
+ // if err != nil {
|
|
|
268
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
269
|
+ // }
|
|
|
270
|
+ // if err := transactionContext.StartTransaction(); err != nil {
|
|
|
271
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
272
|
+ // }
|
|
|
273
|
+ // defer func() {
|
|
|
274
|
+ // transactionContext.RollbackTransaction()
|
|
|
275
|
+ // }()
|
|
|
276
|
+ // var loginAccessRepository domain.LoginAccessRepository
|
|
|
277
|
+ // if loginAccessRepository, err = factory.CreateLoginAccessRepository(map[string]interface{}{
|
|
|
278
|
+ // "transactionContext": transactionContext,
|
|
|
279
|
+ // }); err != nil {
|
|
|
280
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
281
|
+ // }
|
|
|
282
|
+ // _, lAccess, err := loginAccessRepository.Find(map[string]interface{}{
|
|
|
283
|
+ // "account": phone,
|
|
|
284
|
+ // "platform": domain.LoginPlatformApp,
|
|
|
285
|
+ // })
|
|
|
286
|
+ // if err != nil {
|
|
|
287
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
288
|
+ // }
|
|
|
289
|
+ // var currentAccess *domain.LoginAccess
|
|
|
290
|
+ // if len(lAccess) > 0 {
|
|
|
291
|
+ // currentAccess = lAccess[0]
|
|
|
292
|
+ // currentAccess.UpdatedTime = time.Now()
|
|
|
293
|
+ // } else {
|
|
|
294
|
+ // currentAccess = &domain.LoginAccess{
|
|
|
295
|
+ // UserBaseId: ltoken.UserBaseId,
|
|
|
296
|
+ // UserId: ltoken.UserId,
|
|
|
297
|
+ // Account: ltoken.Account,
|
|
|
298
|
+ // Platform: domain.LoginPlatformApp,
|
|
|
299
|
+ // CompanyId: ltoken.CompanyId,
|
|
|
300
|
+ // OrganizationId: ltoken.OrgId,
|
|
|
301
|
+ // AccessToken: "",
|
|
|
302
|
+ // RefreshToken: "",
|
|
|
303
|
+ // AccessExpired: 0,
|
|
|
304
|
+ // RefreshExpired: 0,
|
|
|
305
|
+ // CreatedTime: time.Now(),
|
|
|
306
|
+ // UpdatedTime: time.Now(),
|
|
|
307
|
+ // }
|
|
|
308
|
+ // }
|
|
|
309
|
+ // accessTokenStr, err := ltoken.GenerateAccessToken()
|
|
|
310
|
+ // if err != nil {
|
|
|
311
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
312
|
+ // }
|
|
|
313
|
+ // currentAccess.AccessToken = accessTokenStr
|
|
|
314
|
+ // currentAccess.AccessExpired = ltoken.ExpiresAt
|
|
|
315
|
+ // refreshTokenStr, err := ltoken.GenerateRefreshToken()
|
|
|
316
|
+ // if err != nil {
|
|
|
317
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
318
|
+ // }
|
|
|
319
|
+ // currentAccess.RefreshToken = refreshTokenStr
|
|
|
320
|
+ // currentAccess.RefreshExpired = ltoken.ExpiresAt
|
|
|
321
|
+ // //先存数据库
|
|
|
322
|
+ // _, err = loginAccessRepository.Save(currentAccess)
|
|
|
323
|
+ // if err != nil {
|
|
|
324
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
325
|
+ // }
|
|
|
326
|
+ // if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
327
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
328
|
+ // }
|
|
|
329
|
+ // //后处理redis缓存
|
|
|
330
|
+ // tokenCache := cache.LoginTokenCache{}
|
|
|
331
|
+ // tokenCache.RemoveAccessToken(currentAccess.Account, domain.LoginPlatformApp)
|
|
|
332
|
+ // tokenCache.RemoveRefreshToken(currentAccess.Account, domain.LoginPlatformApp)
|
|
|
333
|
+ // tokenCache.SaveAccessToken(currentAccess)
|
|
|
334
|
+ // tokenCache.SaveRefreshToken(currentAccess)
|
|
|
335
|
+ // nowTime := time.Now().Unix()
|
|
|
336
|
+ // return map[string]interface{}{
|
|
|
337
|
+ // "refreshToken": accessTokenStr,
|
|
|
338
|
+ // "accessToken": refreshTokenStr,
|
|
|
339
|
+ // "expiresIn": currentAccess.AccessExpired - nowTime,
|
|
|
340
|
+ // }, nil
|
|
|
341
|
+ return token, err
|
|
|
342
|
+}
|
|
|
343
|
+
|
|
|
344
|
+//GetUserMenus 获取用户信息
|
|
|
345
|
+func (srv AuthService) GetUserInfo(userInfoCommand *command.UserInfoCommand) (interface{}, error) {
|
|
|
346
|
+ user, err := srv.getUserInfo(userInfoCommand.Operator)
|
|
|
347
|
+ if err != nil {
|
|
|
348
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
349
|
+ }
|
|
|
350
|
+ return map[string]interface{}{
|
|
|
351
|
+ "user": user,
|
|
|
352
|
+ }, nil
|
|
|
353
|
+}
|
|
|
354
|
+
|
|
|
355
|
+//GetUserMenus 获取用户菜单
|
|
|
356
|
+func (srv AuthService) GetUserMenus(userMenusCommand *command.UserMenusCommand) (interface{}, error) {
|
|
|
357
|
+ creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
358
|
+ userMenusCommand.Operator)
|
|
|
359
|
+ resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
|
|
|
360
|
+ UserId: int(userMenusCommand.Operator.UserId),
|
|
|
361
|
+ })
|
|
|
362
|
+ if err != nil {
|
|
|
363
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
364
|
+ }
|
|
|
365
|
+ return map[string]interface{}{
|
|
|
366
|
+ "accessMenus": resultMenu.Menus,
|
|
|
367
|
+ }, nil
|
|
|
368
|
+}
|
|
|
369
|
+
|
|
|
370
|
+//GetUserMenus 获取用户组织
|
|
|
371
|
+func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (interface{}, error) {
|
|
|
372
|
+ creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(userOrgCommand.Operator)
|
|
|
373
|
+ result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
374
|
+ Offset: 0,
|
|
|
375
|
+ Limit: 100,
|
|
|
376
|
+ UserBaseId: userOrgCommand.Operator.UserBaseId,
|
|
|
377
|
+ UserType: domain.UserTypeEmployee,
|
|
|
378
|
+ EnableStatus: domain.UserStatusEnable,
|
|
|
379
|
+ PullRealTime: true,
|
|
|
380
|
+ })
|
|
|
381
|
+ if err != nil {
|
|
|
382
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
383
|
+ }
|
|
|
384
|
+ var res = make([]interface{}, 0)
|
|
|
385
|
+ for i := range result.Users {
|
|
|
386
|
+ for j := range result.Users[i].UserOrg {
|
|
|
387
|
+ org := result.Users[i].UserOrg[j]
|
|
|
388
|
+ res = append(res, map[string]interface{}{
|
|
|
389
|
+ "orgId": org.OrgID,
|
|
|
390
|
+ "orgName": org.OrgName,
|
|
|
391
|
+ })
|
|
|
392
|
+ }
|
|
|
393
|
+ }
|
|
|
394
|
+ return res, nil
|
|
|
395
|
+}
|
|
|
396
|
+
|
|
|
397
|
+//OrgSwitch 组织切换
|
|
|
398
|
+func (srv AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (interface{}, error) {
|
|
|
399
|
+
|
|
|
400
|
+ return nil, nil
|
|
|
401
|
+}
|
|
|
402
|
+
|
|
|
403
|
+// CompanySignUp 企业注册
|
|
|
404
|
+func (srv AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUpCommand) (interface{}, error) {
|
|
|
405
|
+ //TODO:验证码验证测试去掉,后期恢复回来
|
|
|
406
|
+ //smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
|
|
|
407
|
+ //err := smsServeGateway.CheckSmsCode(companySignUpCommand.Phone, companySignUpCommand.SmsCode)
|
|
|
408
|
+ //if err != nil {
|
|
|
409
|
+ // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
410
|
+ //}
|
241
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
411
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
242
|
- userSeachResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
243
|
- Phone: phone,
|
412
|
+ result, err := creationUserGateway.AuthCompanySignUp(allied_creation_user.ReqAuthCompanySignUp{
|
|
|
413
|
+ CompanyName: companySignUpCommand.CompanyName,
|
|
|
414
|
+ Phone: companySignUpCommand.Phone,
|
|
|
415
|
+ Password: companySignUpCommand.Password,
|
|
|
416
|
+ Contacts: companySignUpCommand.Contacts,
|
|
|
417
|
+ IndustryCategory: companySignUpCommand.IndustryCategory,
|
|
|
418
|
+ Scale: companySignUpCommand.Scale,
|
|
|
419
|
+ })
|
|
|
420
|
+ if err != nil {
|
|
|
421
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
422
|
+ }
|
|
|
423
|
+ return result, err
|
|
|
424
|
+}
|
|
|
425
|
+
|
|
|
426
|
+// ResetPassword 重置密码(找回密码)
|
|
|
427
|
+func (srv AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) {
|
|
|
428
|
+ if err := resetPasswordCommand.ValidateCommand(); err != nil {
|
|
|
429
|
+ return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
430
|
+ }
|
|
|
431
|
+ //var phone string
|
|
|
432
|
+ pcc := cache.PhoneCheckCache{}
|
|
|
433
|
+ var item = &cache.PhoneCheckItem{}
|
|
|
434
|
+ if err := pcc.Get(resetPasswordCommand.SmsCodeIdentity, item); err != nil {
|
|
|
435
|
+ log.Logger.Error(err.Error())
|
|
|
436
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, "验证码已失效")
|
|
|
437
|
+ }
|
|
|
438
|
+ // 2.重置密码
|
|
|
439
|
+ creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
440
|
+ result, err := creationUserGateway.AuthResetPassword(allied_creation_user.ReqAuthResetPassword{
|
|
|
441
|
+ Phone: item.Phone,
|
|
|
442
|
+ Password: resetPasswordCommand.Password,
|
|
|
443
|
+ })
|
|
|
444
|
+ if err != nil {
|
|
|
445
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
446
|
+ }
|
|
|
447
|
+ return result, err
|
|
|
448
|
+}
|
|
|
449
|
+
|
|
|
450
|
+func (srv AuthService) getUserInfo(operator domain.Operator) (interface{}, error) {
|
|
|
451
|
+ creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
452
|
+ operator)
|
|
|
453
|
+ resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
|
|
|
454
|
+ UserId: int(operator.UserId),
|
|
|
455
|
+ })
|
|
|
456
|
+ if err != nil {
|
|
|
457
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
458
|
+ }
|
|
|
459
|
+ var user = map[string]interface{}{
|
|
|
460
|
+ "userId": resultUser.UserId,
|
|
|
461
|
+ "userInfo": map[string]interface{}{
|
|
|
462
|
+ "userName": resultUser.UserInfo.UserName,
|
|
|
463
|
+ "userPhone": resultUser.UserInfo.Phone,
|
|
|
464
|
+ "userAvatar": resultUser.UserInfo.Avatar,
|
|
|
465
|
+ //"userCode": resultUser.UserInfo.UserCode,
|
|
|
466
|
+ "email": resultUser.UserInfo.Email,
|
|
|
467
|
+ },
|
|
|
468
|
+ "department": resultUser.Department,
|
|
|
469
|
+ "company": map[string]interface{}{
|
|
|
470
|
+ "companyId": resultUser.Company.CompanyId,
|
|
|
471
|
+ "companyName": resultUser.Company.CompanyName,
|
|
|
472
|
+ "logo": resultUser.Company.Log,
|
|
|
473
|
+ },
|
|
|
474
|
+ "im": resultUser.IM,
|
|
|
475
|
+ "org": resultUser.Org,
|
|
|
476
|
+ }
|
|
|
477
|
+ return user, nil
|
|
|
478
|
+}
|
|
|
479
|
+
|
|
|
480
|
+func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginToken) (interface{}, error) {
|
|
|
481
|
+ creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
482
|
+ userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
483
|
+ Phone: ltoken.Account,
|
244
|
})
|
484
|
})
|
245
|
if err != nil {
|
485
|
if err != nil {
|
246
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "用户信息获取失败,"+err.Error())
|
486
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "用户信息获取失败,"+err.Error())
|
|
@@ -248,10 +488,10 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
|
@@ -248,10 +488,10 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
248
|
//判定当前凭证的companyId,OrganizationId 是否在用户列表中
|
488
|
//判定当前凭证的companyId,OrganizationId 是否在用户列表中
|
249
|
var currentOrgIsOK bool
|
489
|
var currentOrgIsOK bool
|
250
|
loopUser1:
|
490
|
loopUser1:
|
251
|
- for _, v := range userSeachResult.Users {
|
491
|
+ for _, v := range userSearchResult.Users {
|
252
|
if v.Company.CompanyId == int(ltoken.CompanyId) {
|
492
|
if v.Company.CompanyId == int(ltoken.CompanyId) {
|
253
|
for _, vv := range v.UserOrg {
|
493
|
for _, vv := range v.UserOrg {
|
254
|
- if vv.OrgID == int(ltoken.OrgId) {
|
494
|
+ if vv.OrgID == int(ltoken.OrgId) || vv.OrgID == int(operator.OrgId) {
|
255
|
currentOrgIsOK = true
|
495
|
currentOrgIsOK = true
|
256
|
break loopUser1
|
496
|
break loopUser1
|
257
|
}
|
497
|
}
|
|
@@ -279,7 +519,7 @@ loopUser1: |
|
@@ -279,7 +519,7 @@ loopUser1: |
279
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
519
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
280
|
}
|
520
|
}
|
281
|
_, lAccess, err := loginAccessRepository.Find(map[string]interface{}{
|
521
|
_, lAccess, err := loginAccessRepository.Find(map[string]interface{}{
|
282
|
- "account": phone,
|
522
|
+ "account": ltoken.Account,
|
283
|
"platform": domain.LoginPlatformApp,
|
523
|
"platform": domain.LoginPlatformApp,
|
284
|
})
|
524
|
})
|
285
|
if err != nil {
|
525
|
if err != nil {
|
|
@@ -338,125 +578,3 @@ loopUser1: |
|
@@ -338,125 +578,3 @@ loopUser1: |
338
|
"expiresIn": currentAccess.AccessExpired - nowTime,
|
578
|
"expiresIn": currentAccess.AccessExpired - nowTime,
|
339
|
}, nil
|
579
|
}, nil
|
340
|
} |
580
|
} |
341
|
-
|
|
|
342
|
-//GetUserMenus 获取用户信息
|
|
|
343
|
-func (srv AuthService) GetUserInfo(userInfoCommand *command.UserInfoCommand) (interface{}, error) {
|
|
|
344
|
- creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
345
|
- userInfoCommand.Operator)
|
|
|
346
|
- resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
|
|
|
347
|
- UserId: int(userInfoCommand.Operator.UserId),
|
|
|
348
|
- })
|
|
|
349
|
- if err != nil {
|
|
|
350
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
351
|
- }
|
|
|
352
|
- var user = map[string]interface{}{
|
|
|
353
|
- "userId": resultUser.UserId,
|
|
|
354
|
- "userInfo": map[string]interface{}{
|
|
|
355
|
- "userName": resultUser.UserInfo.UserName,
|
|
|
356
|
- "userPhone": resultUser.UserInfo.Phone,
|
|
|
357
|
- "userAvatar": resultUser.UserInfo.Avatar,
|
|
|
358
|
- //"userCode": resultUser.UserInfo.UserCode,
|
|
|
359
|
- "email": resultUser.UserInfo.Email,
|
|
|
360
|
- },
|
|
|
361
|
- "department": resultUser.Department,
|
|
|
362
|
- "company": map[string]interface{}{
|
|
|
363
|
- "companyId": resultUser.Company.CompanyId,
|
|
|
364
|
- "companyName": resultUser.Company.CompanyName,
|
|
|
365
|
- "logo": resultUser.Company.Log,
|
|
|
366
|
- },
|
|
|
367
|
- "im": resultUser.IM,
|
|
|
368
|
- "org": resultUser.Org,
|
|
|
369
|
- }
|
|
|
370
|
-
|
|
|
371
|
- return map[string]interface{}{
|
|
|
372
|
- "user": user,
|
|
|
373
|
- }, nil
|
|
|
374
|
-}
|
|
|
375
|
-
|
|
|
376
|
-//GetUserMenus 获取用户菜单
|
|
|
377
|
-func (srv AuthService) GetUserMenus(userMenusCommand *command.UserMenusCommand) (interface{}, error) {
|
|
|
378
|
- creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
379
|
- userMenusCommand.Operator)
|
|
|
380
|
- resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
|
|
|
381
|
- UserId: int(userMenusCommand.Operator.UserId),
|
|
|
382
|
- })
|
|
|
383
|
- if err != nil {
|
|
|
384
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
385
|
- }
|
|
|
386
|
- return map[string]interface{}{
|
|
|
387
|
- "accessMenus": resultMenu.Menus,
|
|
|
388
|
- }, nil
|
|
|
389
|
-}
|
|
|
390
|
-
|
|
|
391
|
-//GetUserMenus 获取用户组织
|
|
|
392
|
-func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (interface{}, error) {
|
|
|
393
|
- creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(userOrgCommand.Operator)
|
|
|
394
|
- result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
395
|
- Offset: 0,
|
|
|
396
|
- Limit: 100,
|
|
|
397
|
- UserBaseId: userOrgCommand.Operator.UserBaseId,
|
|
|
398
|
- UserType: domain.UserTypeEmployee,
|
|
|
399
|
- EnableStatus: domain.UserStatusEnable,
|
|
|
400
|
- PullRealTime: true,
|
|
|
401
|
- })
|
|
|
402
|
- if err != nil {
|
|
|
403
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
404
|
- }
|
|
|
405
|
- var res = make([]interface{}, 0)
|
|
|
406
|
- for i := range result.Users {
|
|
|
407
|
- for j := range result.Users[i].UserOrg {
|
|
|
408
|
- org := result.Users[i].UserOrg[j]
|
|
|
409
|
- res = append(res, map[string]interface{}{
|
|
|
410
|
- "orgId": org.OrgID,
|
|
|
411
|
- "orgName": org.OrgName,
|
|
|
412
|
- })
|
|
|
413
|
- }
|
|
|
414
|
- }
|
|
|
415
|
- return res, nil
|
|
|
416
|
-}
|
|
|
417
|
-
|
|
|
418
|
-// CompanySignUp 企业注册
|
|
|
419
|
-func (srv AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUpCommand) (interface{}, error) {
|
|
|
420
|
- smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
|
|
|
421
|
- err := smsServeGateway.CheckSmsCode(companySignUpCommand.Phone, companySignUpCommand.SmsCode)
|
|
|
422
|
- if err != nil {
|
|
|
423
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
424
|
- }
|
|
|
425
|
- creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
426
|
- result, err := creationUserGateway.AuthCompanySignUp(allied_creation_user.ReqAuthCompanySignUp{
|
|
|
427
|
- CompanyName: companySignUpCommand.CompanyName,
|
|
|
428
|
- Phone: companySignUpCommand.Phone,
|
|
|
429
|
- Password: companySignUpCommand.Password,
|
|
|
430
|
- Contacts: companySignUpCommand.Contacts,
|
|
|
431
|
- IndustryCategory: companySignUpCommand.IndustryCategory,
|
|
|
432
|
- Scale: companySignUpCommand.Scale,
|
|
|
433
|
- })
|
|
|
434
|
- if err != nil {
|
|
|
435
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
436
|
- }
|
|
|
437
|
- return result, err
|
|
|
438
|
-}
|
|
|
439
|
-
|
|
|
440
|
-// ResetPassword 重置密码(找回密码)
|
|
|
441
|
-func (srv AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) {
|
|
|
442
|
- if err := resetPasswordCommand.ValidateCommand(); err != nil {
|
|
|
443
|
- return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
444
|
- }
|
|
|
445
|
- //var phone string
|
|
|
446
|
- pcc := cache.PhoneCheckCache{}
|
|
|
447
|
- var item = &cache.PhoneCheckItem{}
|
|
|
448
|
- if err := pcc.Get(resetPasswordCommand.SmsCodeIdentity, item); err != nil {
|
|
|
449
|
- log.Logger.Error(err.Error())
|
|
|
450
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, "验证码已失效")
|
|
|
451
|
- }
|
|
|
452
|
- // 2.重置密码
|
|
|
453
|
- creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
454
|
- result, err := creationUserGateway.AuthResetPassword(allied_creation_user.ReqAuthResetPassword{
|
|
|
455
|
- Phone: item.Phone,
|
|
|
456
|
- Password: resetPasswordCommand.Password,
|
|
|
457
|
- })
|
|
|
458
|
- if err != nil {
|
|
|
459
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
460
|
- }
|
|
|
461
|
- return result, err
|
|
|
462
|
-} |
|
|