...
|
...
|
@@ -338,7 +338,7 @@ func (srv AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
|
|
// "accessToken": refreshTokenStr,
|
|
|
// "expiresIn": currentAccess.AccessExpired - nowTime,
|
|
|
// }, nil
|
|
|
return token, err
|
|
|
return token["token"], err
|
|
|
}
|
|
|
|
|
|
//GetUserMenus 获取用户信息
|
...
|
...
|
@@ -396,8 +396,43 @@ func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (inter |
|
|
|
|
|
//OrgSwitch 组织切换
|
|
|
func (srv AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (interface{}, error) {
|
|
|
|
|
|
return nil, nil
|
|
|
if err := switchOrgCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken := domain.LoginToken{}
|
|
|
err := ltoken.ParseToken(switchOrgCommand.Operator.Token)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "accessToken 不可用,"+err.Error())
|
|
|
}
|
|
|
ltoken.OrgId = switchOrgCommand.OrgId
|
|
|
token, err := srv.getToken(domain.Operator{}, ltoken)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
var userId int64
|
|
|
if v, ok := token["userId"]; ok {
|
|
|
if userId, ok = v.(int64); !ok {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "用户不存在")
|
|
|
}
|
|
|
}
|
|
|
user, err := srv.getUserInfo(domain.Operator{UserId: userId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
switchOrgCommand.Operator)
|
|
|
resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
|
|
|
UserId: int(userId),
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
var res = map[string]interface{}{
|
|
|
"user": user,
|
|
|
"accessMenus": resultMenu.Menus,
|
|
|
"token": token["token"],
|
|
|
}
|
|
|
return res, nil
|
|
|
}
|
|
|
|
|
|
// CompanySignUp 企业注册
|
...
|
...
|
@@ -477,7 +512,7 @@ func (srv AuthService) getUserInfo(operator domain.Operator) (interface{}, error |
|
|
return user, nil
|
|
|
}
|
|
|
|
|
|
func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginToken) (interface{}, error) {
|
|
|
func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginToken) (map[string]interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
Phone: ltoken.Account,
|
...
|
...
|
@@ -487,16 +522,18 @@ func (srv AuthService) getToken(operator domain.Operator, ltoken domain.LoginTok |
|
|
}
|
|
|
//判定当前凭证的companyId,OrganizationId 是否在用户列表中
|
|
|
var currentOrgIsOK bool
|
|
|
var currentUserId int64
|
|
|
loopUser1:
|
|
|
for _, v := range userSearchResult.Users {
|
|
|
if v.Company.CompanyId == int(ltoken.CompanyId) {
|
|
|
//if v.Company.CompanyId == int(ltoken.CompanyId) {
|
|
|
for _, vv := range v.UserOrg {
|
|
|
if vv.OrgID == int(ltoken.OrgId) || vv.OrgID == int(operator.OrgId) {
|
|
|
if vv.OrgID == int(ltoken.OrgId) {
|
|
|
currentOrgIsOK = true
|
|
|
currentUserId = int64(v.UserId)
|
|
|
break loopUser1
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//}
|
|
|
}
|
|
|
if !currentOrgIsOK {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
...
|
...
|
@@ -572,9 +609,13 @@ loopUser1: |
|
|
tokenCache.SaveAccessToken(currentAccess)
|
|
|
tokenCache.SaveRefreshToken(currentAccess)
|
|
|
nowTime := time.Now().Unix()
|
|
|
return map[string]interface{}{
|
|
|
token := map[string]interface{}{
|
|
|
"refreshToken": accessTokenStr,
|
|
|
"accessToken": refreshTokenStr,
|
|
|
"expiresIn": currentAccess.AccessExpired - nowTime,
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"token": token,
|
|
|
"userId": currentUserId,
|
|
|
}, nil
|
|
|
} |
...
|
...
|
|