|
@@ -338,7 +338,7 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
|
@@ -338,7 +338,7 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
338
|
// "accessToken": refreshTokenStr,
|
338
|
// "accessToken": refreshTokenStr,
|
339
|
// "expiresIn": currentAccess.AccessExpired - nowTime,
|
339
|
// "expiresIn": currentAccess.AccessExpired - nowTime,
|
340
|
// }, nil
|
340
|
// }, nil
|
341
|
- return token, err
|
341
|
+ return token["token"], err
|
342
|
}
|
342
|
}
|
343
|
|
343
|
|
344
|
//GetUserMenus 获取用户信息
|
344
|
//GetUserMenus 获取用户信息
|
|
@@ -396,8 +396,43 @@ func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (inter |
|
@@ -396,8 +396,43 @@ func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (inter |
396
|
|
396
|
|
397
|
//OrgSwitch 组织切换
|
397
|
//OrgSwitch 组织切换
|
398
|
func (srv AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (interface{}, error) {
|
398
|
func (srv AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (interface{}, error) {
|
399
|
-
|
|
|
400
|
- return nil, nil
|
399
|
+ if err := switchOrgCommand.ValidateCommand(); err != nil {
|
|
|
400
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
401
|
+ }
|
|
|
402
|
+ ltoken := domain.LoginToken{}
|
|
|
403
|
+ err := ltoken.ParseToken(switchOrgCommand.Operator.Token)
|
|
|
404
|
+ if err != nil {
|
|
|
405
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, "accessToken 不可用,"+err.Error())
|
|
|
406
|
+ }
|
|
|
407
|
+ ltoken.OrgId = switchOrgCommand.OrgId
|
|
|
408
|
+ token, err := srv.getToken(domain.Operator{}, ltoken)
|
|
|
409
|
+ if err != nil {
|
|
|
410
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
411
|
+ }
|
|
|
412
|
+ var userId int64
|
|
|
413
|
+ if v, ok := token["userId"]; ok {
|
|
|
414
|
+ if userId, ok = v.(int64); !ok {
|
|
|
415
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, "用户不存在")
|
|
|
416
|
+ }
|
|
|
417
|
+ }
|
|
|
418
|
+ user, err := srv.getUserInfo(domain.Operator{UserId: userId})
|
|
|
419
|
+ if err != nil {
|
|
|
420
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
421
|
+ }
|
|
|
422
|
+ creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
423
|
+ switchOrgCommand.Operator)
|
|
|
424
|
+ resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
|
|
|
425
|
+ UserId: int(userId),
|
|
|
426
|
+ })
|
|
|
427
|
+ if err != nil {
|
|
|
428
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
429
|
+ }
|
|
|
430
|
+ var res = map[string]interface{}{
|
|
|
431
|
+ "user": user,
|
|
|
432
|
+ "accessMenus": resultMenu.Menus,
|
|
|
433
|
+ "token": token["token"],
|
|
|
434
|
+ }
|
|
|
435
|
+ return res, nil
|
401
|
}
|
436
|
}
|
402
|
|
437
|
|
403
|
// CompanySignUp 企业注册
|
438
|
// CompanySignUp 企业注册
|
|
@@ -477,7 +512,7 @@ func (srv AuthService) getUserInfo(operator domain.Operator) (interface{}, error |
|
@@ -477,7 +512,7 @@ func (srv AuthService) getUserInfo(operator domain.Operator) (interface{}, error |
477
|
return user, nil
|
512
|
return user, nil
|
478
|
}
|
513
|
}
|
479
|
|
514
|
|
480
|
-func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginToken) (interface{}, error) {
|
515
|
+func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginToken) (map[string]interface{}, error) {
|
481
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
516
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
482
|
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
517
|
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
483
|
Phone: ltoken.Account,
|
518
|
Phone: ltoken.Account,
|
|
@@ -487,16 +522,18 @@ func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginTok |
|
@@ -487,16 +522,18 @@ func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginTok |
487
|
}
|
522
|
}
|
488
|
//判定当前凭证的companyId,OrganizationId 是否在用户列表中
|
523
|
//判定当前凭证的companyId,OrganizationId 是否在用户列表中
|
489
|
var currentOrgIsOK bool
|
524
|
var currentOrgIsOK bool
|
|
|
525
|
+ var currentUserId int64
|
490
|
loopUser1:
|
526
|
loopUser1:
|
491
|
for _, v := range userSearchResult.Users {
|
527
|
for _, v := range userSearchResult.Users {
|
492
|
- if v.Company.CompanyId == int(ltoken.CompanyId) {
|
|
|
493
|
- for _, vv := range v.UserOrg {
|
|
|
494
|
- if vv.OrgID == int(ltoken.OrgId) || vv.OrgID == int(operator.OrgId) {
|
|
|
495
|
- currentOrgIsOK = true
|
|
|
496
|
- break loopUser1
|
|
|
497
|
- }
|
528
|
+ //if v.Company.CompanyId == int(ltoken.CompanyId) {
|
|
|
529
|
+ for _, vv := range v.UserOrg {
|
|
|
530
|
+ if vv.OrgID == int(ltoken.OrgId) {
|
|
|
531
|
+ currentOrgIsOK = true
|
|
|
532
|
+ currentUserId = int64(v.UserId)
|
|
|
533
|
+ break loopUser1
|
498
|
}
|
534
|
}
|
499
|
}
|
535
|
}
|
|
|
536
|
+ //}
|
500
|
}
|
537
|
}
|
501
|
if !currentOrgIsOK {
|
538
|
if !currentOrgIsOK {
|
502
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
539
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
|
@@ -572,9 +609,13 @@ loopUser1: |
|
@@ -572,9 +609,13 @@ loopUser1: |
572
|
tokenCache.SaveAccessToken(currentAccess)
|
609
|
tokenCache.SaveAccessToken(currentAccess)
|
573
|
tokenCache.SaveRefreshToken(currentAccess)
|
610
|
tokenCache.SaveRefreshToken(currentAccess)
|
574
|
nowTime := time.Now().Unix()
|
611
|
nowTime := time.Now().Unix()
|
575
|
- return map[string]interface{}{
|
612
|
+ token := map[string]interface{}{
|
576
|
"refreshToken": accessTokenStr,
|
613
|
"refreshToken": accessTokenStr,
|
577
|
"accessToken": refreshTokenStr,
|
614
|
"accessToken": refreshTokenStr,
|
578
|
"expiresIn": currentAccess.AccessExpired - nowTime,
|
615
|
"expiresIn": currentAccess.AccessExpired - nowTime,
|
|
|
616
|
+ }
|
|
|
617
|
+ return map[string]interface{}{
|
|
|
618
|
+ "token": token,
|
|
|
619
|
+ "userId": currentUserId,
|
579
|
}, nil
|
620
|
}, nil
|
580
|
} |
621
|
} |