...
|
...
|
@@ -155,20 +155,17 @@ func (svr AuthService) SignInPassword(account string, password string, loginPlat |
|
|
if err != nil {
|
|
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken := domain.LoginToken{
|
|
|
loginToken := domain.LoginToken{
|
|
|
UserId: 0,
|
|
|
Account: account,
|
|
|
Platform: loginPlatform,
|
|
|
CompanyId: 0,
|
|
|
}
|
|
|
authcode, err := ltoken.GenerateAuthCode()
|
|
|
authCode, err := loginToken.GenerateAuthCode()
|
|
|
if err != nil {
|
|
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//result := map[string]string{
|
|
|
// "authCode": authcode,
|
|
|
//}
|
|
|
return authcode, nil
|
|
|
return authCode, nil
|
|
|
}
|
|
|
|
|
|
//SignInCaptcha 使用手机验证码登录
|
...
|
...
|
@@ -178,17 +175,17 @@ func (svr AuthService) SignInCaptcha(phone string, captcha string, loginPlatform |
|
|
if err != nil {
|
|
|
return "", application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken := domain.LoginToken{
|
|
|
loginToken := domain.LoginToken{
|
|
|
UserId: 0,
|
|
|
Account: phone,
|
|
|
Platform: loginPlatform,
|
|
|
CompanyId: 0,
|
|
|
}
|
|
|
authcode, err := ltoken.GenerateAuthCode()
|
|
|
authCode, err := loginToken.GenerateAuthCode()
|
|
|
if err != nil {
|
|
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return authcode, nil
|
|
|
return authCode, nil
|
|
|
}
|
|
|
|
|
|
//GetAuthAccessToken 获取令牌Token
|
...
|
...
|
@@ -196,13 +193,13 @@ func (svr AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke |
|
|
if err := accessTokenCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken := &domain.LoginToken{}
|
|
|
err := ltoken.ParseToken(accessTokenCommand.AuthCode)
|
|
|
loginToken := &domain.LoginToken{}
|
|
|
err := loginToken.ParseToken(accessTokenCommand.AuthCode)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken.Platform = accessTokenCommand.LoginPlatform
|
|
|
result, err := svr.getToken(*ltoken)
|
|
|
loginToken.Platform = accessTokenCommand.LoginPlatform
|
|
|
result, err := svr.getToken(*loginToken)
|
|
|
return result["token"], err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -210,12 +207,12 @@ func (svr AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
|
|
if err := refreshTokenCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken := domain.LoginToken{}
|
|
|
err := ltoken.ParseToken(refreshTokenCommand.RefreshToken)
|
|
|
loginToken := domain.LoginToken{}
|
|
|
err := loginToken.ParseToken(refreshTokenCommand.RefreshToken)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "refreshToken 不可用,"+err.Error())
|
|
|
}
|
|
|
token, err := svr.getToken(ltoken)
|
|
|
token, err := svr.getToken(loginToken)
|
|
|
return map[string]interface{}{
|
|
|
"access": token["token"],
|
|
|
}, err
|
...
|
...
|
@@ -281,13 +278,13 @@ func (svr AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (in |
|
|
if err := switchOrgCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ltoken := domain.LoginToken{}
|
|
|
err := ltoken.ParseToken(switchOrgCommand.Operator.Token)
|
|
|
loginToken := domain.LoginToken{}
|
|
|
err := loginToken.ParseToken(switchOrgCommand.Operator.Token)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "accessToken 不可用,"+err.Error())
|
|
|
}
|
|
|
ltoken.OrgId = switchOrgCommand.OrgId
|
|
|
token, err := svr.getToken(ltoken)
|
|
|
loginToken.OrgId = switchOrgCommand.OrgId
|
|
|
token, err := svr.getToken(loginToken)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -394,10 +391,10 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error |
|
|
return user, nil
|
|
|
}
|
|
|
|
|
|
func (svr AuthService) getToken(ltoken domain.LoginToken) (map[string]interface{}, error) {
|
|
|
func (svr AuthService) getToken(loginToken domain.LoginToken) (map[string]interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
|
|
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
Phone: ltoken.Account,
|
|
|
Phone: loginToken.Account,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "用户信息获取失败,"+err.Error())
|
...
|
...
|
@@ -408,7 +405,7 @@ func (svr AuthService) getToken(ltoken domain.LoginToken) (map[string]interface{ |
|
|
loopUser1:
|
|
|
for _, v := range userSearchResult.Users {
|
|
|
for _, vv := range v.UserOrg {
|
|
|
if vv.OrgID == int(ltoken.OrgId) {
|
|
|
if vv.OrgID == int(loginToken.OrgId) {
|
|
|
currentOrgIsOK = true
|
|
|
currentUser = v
|
|
|
break loopUser1
|
...
|
...
|
@@ -419,7 +416,7 @@ loopUser1: |
|
|
loopUser2:
|
|
|
for _, v := range userSearchResult.Users {
|
|
|
for _, vv := range v.UserOrg {
|
|
|
ltoken.OrgId = int64(vv.OrgID)
|
|
|
loginToken.OrgId = int64(vv.OrgID)
|
|
|
currentOrgIsOK = true
|
|
|
currentUser = v
|
|
|
break loopUser2
|
...
|
...
|
@@ -429,9 +426,9 @@ loopUser1: |
|
|
if !currentOrgIsOK {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
|
|
}
|
|
|
ltoken.UserId = int64(currentUser.UserId)
|
|
|
ltoken.UserBaseId = int64(currentUser.UserBaseId)
|
|
|
ltoken.CompanyId = int64(currentUser.Company.CompanyId)
|
|
|
loginToken.UserId = int64(currentUser.UserId)
|
|
|
loginToken.UserBaseId = int64(currentUser.UserBaseId)
|
|
|
loginToken.CompanyId = int64(currentUser.Company.CompanyId)
|
|
|
|
|
|
// 2. 更新currentAccess信息
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -451,8 +448,8 @@ loopUser1: |
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
_, lAccess, err := loginAccessRepository.Find(map[string]interface{}{
|
|
|
"account": ltoken.Account,
|
|
|
"platform": ltoken.Platform,
|
|
|
"account": loginToken.Account,
|
|
|
"platform": loginToken.Platform,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -461,26 +458,26 @@ loopUser1: |
|
|
if len(lAccess) > 0 {
|
|
|
currentAccess = lAccess[0]
|
|
|
}
|
|
|
currentAccess.UserId = int64(ltoken.UserId)
|
|
|
currentAccess.UserBaseId = int64(ltoken.UserBaseId)
|
|
|
currentAccess.Account = ltoken.Account
|
|
|
currentAccess.Platform = ltoken.Platform
|
|
|
currentAccess.CompanyId = int64(ltoken.CompanyId)
|
|
|
currentAccess.OrganizationId = ltoken.OrgId
|
|
|
currentAccess.UserId = int64(loginToken.UserId)
|
|
|
currentAccess.UserBaseId = int64(loginToken.UserBaseId)
|
|
|
currentAccess.Account = loginToken.Account
|
|
|
currentAccess.Platform = loginToken.Platform
|
|
|
currentAccess.CompanyId = int64(loginToken.CompanyId)
|
|
|
currentAccess.OrganizationId = loginToken.OrgId
|
|
|
currentAccess.UpdatedTime = time.Now()
|
|
|
|
|
|
accessTokenStr, err := ltoken.GenerateAccessToken()
|
|
|
accessTokenStr, err := loginToken.GenerateAccessToken()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
currentAccess.AccessToken = accessTokenStr
|
|
|
currentAccess.AccessExpired = ltoken.ExpiresAt
|
|
|
refreshTokenStr, err := ltoken.GenerateRefreshToken()
|
|
|
currentAccess.AccessExpired = loginToken.ExpiresAt
|
|
|
refreshTokenStr, err := loginToken.GenerateRefreshToken()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
currentAccess.RefreshToken = refreshTokenStr
|
|
|
currentAccess.RefreshExpired = ltoken.ExpiresAt
|
|
|
currentAccess.RefreshExpired = loginToken.ExpiresAt
|
|
|
|
|
|
//存数据库
|
|
|
_, err = loginAccessRepository.Save(currentAccess)
|
...
|
...
|
@@ -493,8 +490,8 @@ loopUser1: |
|
|
|
|
|
//redis缓存
|
|
|
tokenCache := cache.LoginTokenCache{}
|
|
|
tokenCache.RemoveAccessToken(currentAccess.Account, ltoken.Platform)
|
|
|
tokenCache.RemoveRefreshToken(currentAccess.Account, ltoken.Platform)
|
|
|
tokenCache.RemoveAccessToken(currentAccess.Account, loginToken.Platform)
|
|
|
tokenCache.RemoveRefreshToken(currentAccess.Account, loginToken.Platform)
|
|
|
tokenCache.SaveAccessToken(currentAccess)
|
|
|
tokenCache.SaveRefreshToken(currentAccess)
|
|
|
nowTime := time.Now().Unix()
|
...
|
...
|
@@ -514,7 +511,9 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs |
|
|
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(queryParam.Operator)
|
|
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
Phone: queryParam.Phone,
|
|
|
UserBaseId: queryParam.Operator.UserBaseId,
|
|
|
//Phone: queryParam.Phone,
|
|
|
UserType: domain.UserTypeEmployee,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -590,8 +589,8 @@ func (svr *AuthService) CaptchaInit(request *query.CaptchaInitRequest) (interfac |
|
|
var rsp map[string]interface{}
|
|
|
var err error
|
|
|
|
|
|
newGeetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
|
|
|
status, responseBt := newGeetest.PreProcess("", request.UserIp)
|
|
|
lib := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
|
|
|
status, responseBt := lib.PreProcess("", request.UserIp)
|
|
|
var geetestRsp geetest.FailbackRegisterRespnse
|
|
|
json.Unmarshal(responseBt, &geetestRsp)
|
|
|
rspData := map[string]interface{}{
|
...
|
...
|
|