作者 yangfu

增加配置 多端登录控制

@@ -351,11 +351,13 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -351,11 +351,13 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
351 break 351 break
352 case protocol.LoginByCredentials: 352 case protocol.LoginByCredentials:
353 //凭证是否存在 353 //凭证是否存在
  354 + if constant.DISENABLE_MULTI_DEVICE_LOGIN {
354 if credential, e := userAuth.NewRedisUserCredential(request.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) { 355 if credential, e := userAuth.NewRedisUserCredential(request.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
355 log.Debug("凭证过期或者已失效:", request.Phone) 356 log.Debug("凭证过期或者已失效:", request.Phone)
356 err = protocol.NewErrWithMessage(4140, err) 357 err = protocol.NewErrWithMessage(4140, err)
357 return 358 return
358 } 359 }
  360 + }
359 if _, err = utils.ParseJWTToken(request.Credentials); err != nil { 361 if _, err = utils.ParseJWTToken(request.Credentials); err != nil {
360 err = protocol.NewErrWithMessage(4140, err) 362 err = protocol.NewErrWithMessage(4140, err)
361 return 363 return
@@ -419,11 +421,13 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest @@ -419,11 +421,13 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
419 return 421 return
420 } 422 }
421 //凭证是否存在 423 //凭证是否存在
  424 + if constant.DISENABLE_MULTI_DEVICE_LOGIN {
422 if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) { 425 if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
423 log.Debug("凭证过期或者已失效:", claim.Phone) 426 log.Debug("凭证过期或者已失效:", claim.Phone)
424 err = protocol.NewErrWithMessage(4140, err) 427 err = protocol.NewErrWithMessage(4140, err)
425 return 428 return
426 } 429 }
  430 + }
427 loginSvr.Init(claim.Phone) 431 loginSvr.Init(claim.Phone)
428 rsp.Partner, _ = loginSvr.PartnerStaticInfo() 432 rsp.Partner, _ = loginSvr.PartnerStaticInfo()
429 rsp.Manager, _ = loginSvr.ManagerStaticInfo() 433 rsp.Manager, _ = loginSvr.ManagerStaticInfo()
@@ -458,12 +462,14 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( @@ -458,12 +462,14 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
458 err = protocol.NewErrWithMessage(4140, err) 462 err = protocol.NewErrWithMessage(4140, err)
459 return 463 return
460 } 464 }
  465 + if constant.DISENABLE_MULTI_DEVICE_LOGIN {
461 //凭证是否存在 466 //凭证是否存在
462 if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) { 467 if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
463 log.Debug("凭证过期或者已失效:", claim.Phone) 468 log.Debug("凭证过期或者已失效:", claim.Phone)
464 err = protocol.NewErrWithMessage(4140, err) 469 err = protocol.NewErrWithMessage(4140, err)
465 return 470 return
466 } 471 }
  472 + }
467 if company, e := CompanyRepository.FindOne(map[string]interface{}{"id": request.Cid, "enable": 1}); e != nil || company == nil { 473 if company, e := CompanyRepository.FindOne(map[string]interface{}{"id": request.Cid, "enable": 1}); e != nil || company == nil {
468 err = protocol.NewErrWithMessage(10007, err) 474 err = protocol.NewErrWithMessage(10007, err)
469 return 475 return
@@ -3,10 +3,13 @@ package event @@ -3,10 +3,13 @@ package event
3 import ( 3 import (
4 "github.com/tiptok/gocomm/xa/eda" 4 "github.com/tiptok/gocomm/xa/eda"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/event/subscriber" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/event/subscriber"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event"
7 ) 8 )
8 9
9 func InitEventCenter() { 10 func InitEventCenter() {
  11 + if constant.DISENABLE_MULTI_DEVICE_LOGIN {
10 eda.RegisterSubscribe(&event.AccessTokenEvent{}, &subscriber.AuthCacheSubscribe{}) 12 eda.RegisterSubscribe(&event.AccessTokenEvent{}, &subscriber.AuthCacheSubscribe{})
11 eda.RegisterSubscribe(&event.RefreshTokenEvent{}, &subscriber.AuthCacheSubscribe{}) 13 eda.RegisterSubscribe(&event.RefreshTokenEvent{}, &subscriber.AuthCacheSubscribe{})
  14 + }
12 } 15 }
@@ -21,6 +21,9 @@ var DEFAULT_GUEST_COMPANY int = 10011 @@ -21,6 +21,9 @@ var DEFAULT_GUEST_COMPANY int = 10011
21 21
22 var SHARE_SHOP_PREVIEW_IMADGE = "https://media.fjmaimaimai.com/image/default/3E0C7050C13147CE8C7AF86C75F904E9-6-2.jpg" //分享店铺预览图 22 var SHARE_SHOP_PREVIEW_IMADGE = "https://media.fjmaimaimai.com/image/default/3E0C7050C13147CE8C7AF86C75F904E9-6-2.jpg" //分享店铺预览图
23 var WEHAT_MINI_PROGRAM_VERSION_TYPE = 2 //0:正式版 1:开发版 2:体验版 23 var WEHAT_MINI_PROGRAM_VERSION_TYPE = 2 //0:正式版 1:开发版 2:体验版
  24 +
  25 +var DISENABLE_MULTI_DEVICE_LOGIN = false //不允许多端登录 (注:正式环境需要为true 测试环境设为false,方便多个设备测试)
  26 +
24 func init() { 27 func init() {
25 if os.Getenv("LOG_LEVEL") != "" { 28 if os.Getenv("LOG_LEVEL") != "" {
26 LOG_LEVEL = os.Getenv("LOG_LEVEL") 29 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -32,4 +32,7 @@ func init() { @@ -32,4 +32,7 @@ func init() {
32 if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" { 32 if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" {
33 DISABLE_SQL_GENERATE_PRINT = true 33 DISABLE_SQL_GENERATE_PRINT = true
34 } 34 }
  35 + if POSTGRESQL_DB_NAME == "partner" {
  36 + DISENABLE_MULTI_DEVICE_LOGIN = true
  37 + }
35 } 38 }
@@ -3,6 +3,7 @@ package middleware @@ -3,6 +3,7 @@ package middleware
3 import ( 3 import (
4 "github.com/astaxie/beego/context" 4 "github.com/astaxie/beego/context"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
8 "strconv" 9 "strconv"
@@ -39,6 +40,7 @@ func CheckJWTToken(ctx *context.Context) { @@ -39,6 +40,7 @@ func CheckJWTToken(ctx *context.Context) {
39 } else { 40 } else {
40 ctx.Input.SetData("UserId", u.UserId) 41 ctx.Input.SetData("UserId", u.UserId)
41 42
  43 + if constant.DISENABLE_MULTI_DEVICE_LOGIN {
42 // valid token 44 // valid token
43 userPhone, _ := strconv.Atoi(u.Phone) 45 userPhone, _ := strconv.Atoi(u.Phone)
44 tokenAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(userPhone))) 46 tokenAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(userPhone)))
@@ -50,5 +52,6 @@ func CheckJWTToken(ctx *context.Context) { @@ -50,5 +52,6 @@ func CheckJWTToken(ctx *context.Context) {
50 return 52 return
51 } 53 }
52 } 54 }
  55 + }
53 return 56 return
54 } 57 }