|
@@ -155,20 +155,17 @@ func (svr AuthService) SignInPassword(account string, password string, loginPlat |
|
@@ -155,20 +155,17 @@ func (svr AuthService) SignInPassword(account string, password string, loginPlat |
155
|
if err != nil {
|
155
|
if err != nil {
|
156
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
156
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
157
|
}
|
157
|
}
|
158
|
- ltoken := domain.LoginToken{
|
158
|
+ loginToken := domain.LoginToken{
|
159
|
UserId: 0,
|
159
|
UserId: 0,
|
160
|
Account: account,
|
160
|
Account: account,
|
161
|
Platform: loginPlatform,
|
161
|
Platform: loginPlatform,
|
162
|
CompanyId: 0,
|
162
|
CompanyId: 0,
|
163
|
}
|
163
|
}
|
164
|
- authcode, err := ltoken.GenerateAuthCode()
|
164
|
+ authCode, err := loginToken.GenerateAuthCode()
|
165
|
if err != nil {
|
165
|
if err != nil {
|
166
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
166
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
167
|
}
|
167
|
}
|
168
|
- //result := map[string]string{
|
|
|
169
|
- // "authCode": authcode,
|
|
|
170
|
- //}
|
|
|
171
|
- return authcode, nil
|
168
|
+ return authCode, nil
|
172
|
}
|
169
|
}
|
173
|
|
170
|
|
174
|
//SignInCaptcha 使用手机验证码登录
|
171
|
//SignInCaptcha 使用手机验证码登录
|
|
@@ -178,17 +175,17 @@ func (svr AuthService) SignInCaptcha(phone string, captcha string, loginPlatform |
|
@@ -178,17 +175,17 @@ func (svr AuthService) SignInCaptcha(phone string, captcha string, loginPlatform |
178
|
if err != nil {
|
175
|
if err != nil {
|
179
|
return "", application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
176
|
return "", application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
180
|
}
|
177
|
}
|
181
|
- ltoken := domain.LoginToken{
|
178
|
+ loginToken := domain.LoginToken{
|
182
|
UserId: 0,
|
179
|
UserId: 0,
|
183
|
Account: phone,
|
180
|
Account: phone,
|
184
|
Platform: loginPlatform,
|
181
|
Platform: loginPlatform,
|
185
|
CompanyId: 0,
|
182
|
CompanyId: 0,
|
186
|
}
|
183
|
}
|
187
|
- authcode, err := ltoken.GenerateAuthCode()
|
184
|
+ authCode, err := loginToken.GenerateAuthCode()
|
188
|
if err != nil {
|
185
|
if err != nil {
|
189
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
186
|
return "", application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
190
|
}
|
187
|
}
|
191
|
- return authcode, nil
|
188
|
+ return authCode, nil
|
192
|
}
|
189
|
}
|
193
|
|
190
|
|
194
|
//GetAuthAccessToken 获取令牌Token
|
191
|
//GetAuthAccessToken 获取令牌Token
|
|
@@ -196,13 +193,13 @@ func (svr AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke |
|
@@ -196,13 +193,13 @@ func (svr AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke |
196
|
if err := accessTokenCommand.ValidateCommand(); err != nil {
|
193
|
if err := accessTokenCommand.ValidateCommand(); err != nil {
|
197
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
194
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
198
|
}
|
195
|
}
|
199
|
- ltoken := &domain.LoginToken{}
|
|
|
200
|
- err := ltoken.ParseToken(accessTokenCommand.AuthCode)
|
196
|
+ loginToken := &domain.LoginToken{}
|
|
|
197
|
+ err := loginToken.ParseToken(accessTokenCommand.AuthCode)
|
201
|
if err != nil {
|
198
|
if err != nil {
|
202
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
199
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
203
|
}
|
200
|
}
|
204
|
- ltoken.Platform = accessTokenCommand.LoginPlatform
|
|
|
205
|
- result, err := svr.getToken(*ltoken)
|
201
|
+ loginToken.Platform = accessTokenCommand.LoginPlatform
|
|
|
202
|
+ result, err := svr.getToken(*loginToken)
|
206
|
return result["token"], err
|
203
|
return result["token"], err
|
207
|
}
|
204
|
}
|
208
|
|
205
|
|
|
@@ -210,12 +207,12 @@ func (svr AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
|
@@ -210,12 +207,12 @@ func (svr AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.Refre |
210
|
if err := refreshTokenCommand.ValidateCommand(); err != nil {
|
207
|
if err := refreshTokenCommand.ValidateCommand(); err != nil {
|
211
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
208
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
212
|
}
|
209
|
}
|
213
|
- ltoken := domain.LoginToken{}
|
|
|
214
|
- err := ltoken.ParseToken(refreshTokenCommand.RefreshToken)
|
210
|
+ loginToken := domain.LoginToken{}
|
|
|
211
|
+ err := loginToken.ParseToken(refreshTokenCommand.RefreshToken)
|
215
|
if err != nil {
|
212
|
if err != nil {
|
216
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "refreshToken 不可用,"+err.Error())
|
213
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "refreshToken 不可用,"+err.Error())
|
217
|
}
|
214
|
}
|
218
|
- token, err := svr.getToken(ltoken)
|
215
|
+ token, err := svr.getToken(loginToken)
|
219
|
return map[string]interface{}{
|
216
|
return map[string]interface{}{
|
220
|
"access": token["token"],
|
217
|
"access": token["token"],
|
221
|
}, err
|
218
|
}, err
|
|
@@ -281,13 +278,13 @@ func (svr AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (in |
|
@@ -281,13 +278,13 @@ func (svr AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (in |
281
|
if err := switchOrgCommand.ValidateCommand(); err != nil {
|
278
|
if err := switchOrgCommand.ValidateCommand(); err != nil {
|
282
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
279
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
283
|
}
|
280
|
}
|
284
|
- ltoken := domain.LoginToken{}
|
|
|
285
|
- err := ltoken.ParseToken(switchOrgCommand.Operator.Token)
|
281
|
+ loginToken := domain.LoginToken{}
|
|
|
282
|
+ err := loginToken.ParseToken(switchOrgCommand.Operator.Token)
|
286
|
if err != nil {
|
283
|
if err != nil {
|
287
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "accessToken 不可用,"+err.Error())
|
284
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "accessToken 不可用,"+err.Error())
|
288
|
}
|
285
|
}
|
289
|
- ltoken.OrgId = switchOrgCommand.OrgId
|
|
|
290
|
- token, err := svr.getToken(ltoken)
|
286
|
+ loginToken.OrgId = switchOrgCommand.OrgId
|
|
|
287
|
+ token, err := svr.getToken(loginToken)
|
291
|
if err != nil {
|
288
|
if err != nil {
|
292
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
289
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
293
|
}
|
290
|
}
|
|
@@ -394,10 +391,10 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error |
|
@@ -394,10 +391,10 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error |
394
|
return user, nil
|
391
|
return user, nil
|
395
|
}
|
392
|
}
|
396
|
|
393
|
|
397
|
-func (svr AuthService) getToken(ltoken domain.LoginToken) (map[string]interface{}, error) {
|
394
|
+func (svr AuthService) getToken(loginToken domain.LoginToken) (map[string]interface{}, error) {
|
398
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
395
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
|
399
|
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
396
|
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
400
|
- Phone: ltoken.Account,
|
397
|
+ Phone: loginToken.Account,
|
401
|
})
|
398
|
})
|
402
|
if err != nil {
|
399
|
if err != nil {
|
403
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "用户信息获取失败,"+err.Error())
|
400
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "用户信息获取失败,"+err.Error())
|
|
@@ -408,7 +405,7 @@ func (svr AuthService) getToken(ltoken domain.LoginToken) (map[string]interface{ |
|
@@ -408,7 +405,7 @@ func (svr AuthService) getToken(ltoken domain.LoginToken) (map[string]interface{ |
408
|
loopUser1:
|
405
|
loopUser1:
|
409
|
for _, v := range userSearchResult.Users {
|
406
|
for _, v := range userSearchResult.Users {
|
410
|
for _, vv := range v.UserOrg {
|
407
|
for _, vv := range v.UserOrg {
|
411
|
- if vv.OrgID == int(ltoken.OrgId) {
|
408
|
+ if vv.OrgID == int(loginToken.OrgId) {
|
412
|
currentOrgIsOK = true
|
409
|
currentOrgIsOK = true
|
413
|
currentUser = v
|
410
|
currentUser = v
|
414
|
break loopUser1
|
411
|
break loopUser1
|
|
@@ -419,7 +416,7 @@ loopUser1: |
|
@@ -419,7 +416,7 @@ loopUser1: |
419
|
loopUser2:
|
416
|
loopUser2:
|
420
|
for _, v := range userSearchResult.Users {
|
417
|
for _, v := range userSearchResult.Users {
|
421
|
for _, vv := range v.UserOrg {
|
418
|
for _, vv := range v.UserOrg {
|
422
|
- ltoken.OrgId = int64(vv.OrgID)
|
419
|
+ loginToken.OrgId = int64(vv.OrgID)
|
423
|
currentOrgIsOK = true
|
420
|
currentOrgIsOK = true
|
424
|
currentUser = v
|
421
|
currentUser = v
|
425
|
break loopUser2
|
422
|
break loopUser2
|
|
@@ -429,9 +426,9 @@ loopUser1: |
|
@@ -429,9 +426,9 @@ loopUser1: |
429
|
if !currentOrgIsOK {
|
426
|
if !currentOrgIsOK {
|
430
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
427
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
|
431
|
}
|
428
|
}
|
432
|
- ltoken.UserId = int64(currentUser.UserId)
|
|
|
433
|
- ltoken.UserBaseId = int64(currentUser.UserBaseId)
|
|
|
434
|
- ltoken.CompanyId = int64(currentUser.Company.CompanyId)
|
429
|
+ loginToken.UserId = int64(currentUser.UserId)
|
|
|
430
|
+ loginToken.UserBaseId = int64(currentUser.UserBaseId)
|
|
|
431
|
+ loginToken.CompanyId = int64(currentUser.Company.CompanyId)
|
435
|
|
432
|
|
436
|
// 2. 更新currentAccess信息
|
433
|
// 2. 更新currentAccess信息
|
437
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
434
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
@@ -451,8 +448,8 @@ loopUser1: |
|
@@ -451,8 +448,8 @@ loopUser1: |
451
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
448
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
452
|
}
|
449
|
}
|
453
|
_, lAccess, err := loginAccessRepository.Find(map[string]interface{}{
|
450
|
_, lAccess, err := loginAccessRepository.Find(map[string]interface{}{
|
454
|
- "account": ltoken.Account,
|
|
|
455
|
- "platform": ltoken.Platform,
|
451
|
+ "account": loginToken.Account,
|
|
|
452
|
+ "platform": loginToken.Platform,
|
456
|
})
|
453
|
})
|
457
|
if err != nil {
|
454
|
if err != nil {
|
458
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
455
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -461,26 +458,26 @@ loopUser1: |
|
@@ -461,26 +458,26 @@ loopUser1: |
461
|
if len(lAccess) > 0 {
|
458
|
if len(lAccess) > 0 {
|
462
|
currentAccess = lAccess[0]
|
459
|
currentAccess = lAccess[0]
|
463
|
}
|
460
|
}
|
464
|
- currentAccess.UserId = int64(ltoken.UserId)
|
|
|
465
|
- currentAccess.UserBaseId = int64(ltoken.UserBaseId)
|
|
|
466
|
- currentAccess.Account = ltoken.Account
|
|
|
467
|
- currentAccess.Platform = ltoken.Platform
|
|
|
468
|
- currentAccess.CompanyId = int64(ltoken.CompanyId)
|
|
|
469
|
- currentAccess.OrganizationId = ltoken.OrgId
|
461
|
+ currentAccess.UserId = int64(loginToken.UserId)
|
|
|
462
|
+ currentAccess.UserBaseId = int64(loginToken.UserBaseId)
|
|
|
463
|
+ currentAccess.Account = loginToken.Account
|
|
|
464
|
+ currentAccess.Platform = loginToken.Platform
|
|
|
465
|
+ currentAccess.CompanyId = int64(loginToken.CompanyId)
|
|
|
466
|
+ currentAccess.OrganizationId = loginToken.OrgId
|
470
|
currentAccess.UpdatedTime = time.Now()
|
467
|
currentAccess.UpdatedTime = time.Now()
|
471
|
|
468
|
|
472
|
- accessTokenStr, err := ltoken.GenerateAccessToken()
|
469
|
+ accessTokenStr, err := loginToken.GenerateAccessToken()
|
473
|
if err != nil {
|
470
|
if err != nil {
|
474
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
471
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
475
|
}
|
472
|
}
|
476
|
currentAccess.AccessToken = accessTokenStr
|
473
|
currentAccess.AccessToken = accessTokenStr
|
477
|
- currentAccess.AccessExpired = ltoken.ExpiresAt
|
|
|
478
|
- refreshTokenStr, err := ltoken.GenerateRefreshToken()
|
474
|
+ currentAccess.AccessExpired = loginToken.ExpiresAt
|
|
|
475
|
+ refreshTokenStr, err := loginToken.GenerateRefreshToken()
|
479
|
if err != nil {
|
476
|
if err != nil {
|
480
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
477
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
481
|
}
|
478
|
}
|
482
|
currentAccess.RefreshToken = refreshTokenStr
|
479
|
currentAccess.RefreshToken = refreshTokenStr
|
483
|
- currentAccess.RefreshExpired = ltoken.ExpiresAt
|
480
|
+ currentAccess.RefreshExpired = loginToken.ExpiresAt
|
484
|
|
481
|
|
485
|
//存数据库
|
482
|
//存数据库
|
486
|
_, err = loginAccessRepository.Save(currentAccess)
|
483
|
_, err = loginAccessRepository.Save(currentAccess)
|
|
@@ -493,8 +490,8 @@ loopUser1: |
|
@@ -493,8 +490,8 @@ loopUser1: |
493
|
|
490
|
|
494
|
//redis缓存
|
491
|
//redis缓存
|
495
|
tokenCache := cache.LoginTokenCache{}
|
492
|
tokenCache := cache.LoginTokenCache{}
|
496
|
- tokenCache.RemoveAccessToken(currentAccess.Account, ltoken.Platform)
|
|
|
497
|
- tokenCache.RemoveRefreshToken(currentAccess.Account, ltoken.Platform)
|
493
|
+ tokenCache.RemoveAccessToken(currentAccess.Account, loginToken.Platform)
|
|
|
494
|
+ tokenCache.RemoveRefreshToken(currentAccess.Account, loginToken.Platform)
|
498
|
tokenCache.SaveAccessToken(currentAccess)
|
495
|
tokenCache.SaveAccessToken(currentAccess)
|
499
|
tokenCache.SaveRefreshToken(currentAccess)
|
496
|
tokenCache.SaveRefreshToken(currentAccess)
|
500
|
nowTime := time.Now().Unix()
|
497
|
nowTime := time.Now().Unix()
|
|
@@ -514,7 +511,9 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs |
|
@@ -514,7 +511,9 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs |
514
|
|
511
|
|
515
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(queryParam.Operator)
|
512
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(queryParam.Operator)
|
516
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
513
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
517
|
- Phone: queryParam.Phone,
|
514
|
+ UserBaseId: queryParam.Operator.UserBaseId,
|
|
|
515
|
+ //Phone: queryParam.Phone,
|
|
|
516
|
+ UserType: domain.UserTypeEmployee,
|
518
|
})
|
517
|
})
|
519
|
if err != nil {
|
518
|
if err != nil {
|
520
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
519
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -590,8 +589,8 @@ func (svr *AuthService) CaptchaInit(request *query.CaptchaInitRequest) (interfac |
|
@@ -590,8 +589,8 @@ func (svr *AuthService) CaptchaInit(request *query.CaptchaInitRequest) (interfac |
590
|
var rsp map[string]interface{}
|
589
|
var rsp map[string]interface{}
|
591
|
var err error
|
590
|
var err error
|
592
|
|
591
|
|
593
|
- newGeetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
|
|
|
594
|
- status, responseBt := newGeetest.PreProcess("", request.UserIp)
|
592
|
+ lib := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
|
|
|
593
|
+ status, responseBt := lib.PreProcess("", request.UserIp)
|
595
|
var geetestRsp geetest.FailbackRegisterRespnse
|
594
|
var geetestRsp geetest.FailbackRegisterRespnse
|
596
|
json.Unmarshal(responseBt, &geetestRsp)
|
595
|
json.Unmarshal(responseBt, &geetestRsp)
|
597
|
rspData := map[string]interface{}{
|
596
|
rspData := map[string]interface{}{
|