|
@@ -16,21 +16,19 @@ import (
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
- "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
-
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "app.yhyue.com/moapp/jypkg/public"
|
|
|
-
|
|
|
elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
-
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
mgdb "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "app.yhyue.com/moapp/jypkg/identity"
|
|
|
. "app.yhyue.com/moapp/jypkg/identity"
|
|
|
+ "app.yhyue.com/moapp/jypkg/public"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
"github.com/SKatiyar/qr"
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
@@ -597,7 +595,7 @@ func (f *Front) Login(key string) error {
|
|
|
shareid := se.DecodeString(key)
|
|
|
openid := redis.GetStr("sso", "p_usershare_"+shareid)
|
|
|
if openid != "" {
|
|
|
- ok, user, userInfo := FindUserAndCreateSess(openid, f.Session(), "pc", true)
|
|
|
+ ok, user, userInfo := FindUserAndCreateSess(openid, f.Session(), "pc", true, true)
|
|
|
if ok {
|
|
|
(*user)["shareid"] = shareid
|
|
|
f.SetSession("user", *user)
|
|
@@ -771,29 +769,27 @@ func (m *Front) Wxerr() error {
|
|
|
}
|
|
|
|
|
|
//查找用户并创建session
|
|
|
-func FindUserAndCreateSess(openid string, sess *httpsession.Session, typ string, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+func FindUserAndCreateSess(openid string, sess *httpsession.Session, typ string, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
return CreateSession(map[string]interface{}{
|
|
|
"s_m_openid": openid,
|
|
|
"s_unionid": map[string]interface{}{"$ne": openid}, //处理排除未关注用户点击菜单创建的用户
|
|
|
"i_ispush": 1,
|
|
|
- }, sess, typ, flag)
|
|
|
+ }, sess, typ, flag, isSwitchToBestIdentity)
|
|
|
}
|
|
|
-func FindUserAndCreateSessByBaseUserId(userId int64, sess *httpsession.Session, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
-
|
|
|
+func FindUserAndCreateSessByBaseUserId(userId int64, sess *httpsession.Session, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
return CreateSession(map[string]interface{}{
|
|
|
-
|
|
|
"base_user_id": userId,
|
|
|
- }, sess, "pc", flag)
|
|
|
+ }, sess, "pc", flag, isSwitchToBestIdentity)
|
|
|
|
|
|
}
|
|
|
|
|
|
-func FindUserAndCreateSessById(userId primitive.ObjectID, sess *httpsession.Session, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+func FindUserAndCreateSessById(userId primitive.ObjectID, sess *httpsession.Session, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
return CreateSession(map[string]interface{}{
|
|
|
"_id": userId,
|
|
|
- }, sess, "pc", flag)
|
|
|
+ }, sess, "pc", flag, isSwitchToBestIdentity)
|
|
|
}
|
|
|
|
|
|
-func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ string, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ string, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
if q == nil || len(q) == 0 {
|
|
|
return false, nil, nil
|
|
|
}
|
|
@@ -808,9 +804,11 @@ func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ stri
|
|
|
redis.Put("other", jyutil.LoginRedisKey(userid), sess.Id(), 3600*util.IntAllDef(config.Sysconfig["pcSessionTimeout"], 168))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
sessionVal["platform"] = typ
|
|
|
sess.SetMultiple(sessionVal)
|
|
|
+ if isSwitchToBestIdentity {
|
|
|
+ identity.SwitchToBest(util.Int64All(sessionVal["base_user_id"]), sess, config.Middleground)
|
|
|
+ }
|
|
|
s_nickname := util.If(sessionVal["s_nickname"] != nil, sessionVal["s_nickname"], sessionVal["phone"])
|
|
|
if util.ObjToString(s_nickname) == "" {
|
|
|
s_nickname = sessionVal["s_jyname"]
|
|
@@ -845,27 +843,59 @@ func (m *Front) Sess(ostr string) error {
|
|
|
if len(str) == 4 {
|
|
|
userFlag := str[0]
|
|
|
ok := false
|
|
|
- var identity *pb.Identity
|
|
|
if str[1] == "userId" || str[1] == "entUserId" || str[1] == "positionId" {
|
|
|
+ var identity *pb.Identity
|
|
|
+ sessVal := m.Session().GetMultiple()
|
|
|
if str[1] == "userId" {
|
|
|
- identity = config.Middleground.UserCenter.IdentityByUserId(util.Int64All(userFlag))
|
|
|
+ if sessVal["positionType"] == nil || util.IntAll(sessVal["positionType"]) != 0 {
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByUserId(util.Int64All(userFlag))
|
|
|
+ if identity == nil {
|
|
|
+ log.Println("获取用户身份失败", str)
|
|
|
+ }
|
|
|
+ }
|
|
|
} else if str[1] == "entUserId" {
|
|
|
- identity = config.Middleground.UserCenter.IdentityByEntUserId(util.Int64All(userFlag))
|
|
|
+ if sessVal["positionType"] == nil || sessVal["entUserId"] == nil || util.Int64All(sessVal["positionType"]) != 1 || util.Int64All(sessVal["entUserId"]) != util.Int64All(userFlag) {
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByEntUserId(util.Int64All(userFlag))
|
|
|
+ if identity == nil {
|
|
|
+ log.Println("获取用户身份失败", str)
|
|
|
+ }
|
|
|
+ }
|
|
|
} else if str[1] == "positionId" {
|
|
|
- identity = config.Middleground.UserCenter.IdentityByPositionId(util.Int64All(userFlag))
|
|
|
+ if sessVal["positionId"] == nil || util.Int64All(sessVal["positionId"]) != util.Int64All(userFlag) {
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByPositionId(util.Int64All(userFlag))
|
|
|
+ if identity == nil {
|
|
|
+ log.Println("获取用户身份失败", str)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return m.Render("_error.html")
|
|
|
+ }
|
|
|
+ if sessVal["userId"] == nil {
|
|
|
+ if identity != nil {
|
|
|
+ ok, _, _ = FindUserAndCreateSessByBaseUserId(identity.UserId, m.Session(), false, false)
|
|
|
+ if !ok {
|
|
|
+ log.Println("创建session失败", str)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ok = true
|
|
|
}
|
|
|
if identity != nil {
|
|
|
- ok, _, _ = FindUserAndCreateSessByBaseUserId(identity.UserId, m.Session(), false)
|
|
|
+ ok = ok && NewIdentityInfo(identity).Switch(m.Session())
|
|
|
}
|
|
|
} else {
|
|
|
if str[1] == "_id" {
|
|
|
- ok, _, _ = FindUserAndCreateSessById(mgdb.StringTOBsonId(userFlag), m.Session(), false)
|
|
|
+ ok, _, _ = FindUserAndCreateSessById(mgdb.StringTOBsonId(userFlag), m.Session(), false, true)
|
|
|
+ if !ok {
|
|
|
+ log.Println("创建session失败", str)
|
|
|
+ }
|
|
|
} else {
|
|
|
- ok, _, _ = FindUserAndCreateSess(userFlag, m.Session(), "wx", false)
|
|
|
+ ok, _, _ = FindUserAndCreateSess(userFlag, m.Session(), "wx", false, true)
|
|
|
+ if !ok {
|
|
|
+ log.Println("创建session失败", str)
|
|
|
+ }
|
|
|
}
|
|
|
- identity = config.Middleground.UserCenter.IdentityByUserId(util.Int64All(m.GetSession("base_user_id")))
|
|
|
}
|
|
|
- ok = ok && NewIdentityInfo(identity).Switch(m.Session())
|
|
|
if ok {
|
|
|
actionurl := ""
|
|
|
if str[3] == "" {
|
|
@@ -884,6 +914,8 @@ func (m *Front) Sess(ostr string) error {
|
|
|
}
|
|
|
if identity := config.Middleground.UserCenter.IdentityByEntUserId(entUserId); identity != nil {
|
|
|
NewIdentityInfo(identity).Switch(m.Session())
|
|
|
+ } else {
|
|
|
+ log.Println("获取用户身份失败", str)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -915,7 +947,7 @@ func (m *Front) Sess(ostr string) error {
|
|
|
//action走的nginx配置,需要单独在sess中判断
|
|
|
for k, v := range config.PhoneFilterConfig["sessUrl"].(map[string]interface{}) {
|
|
|
if strings.Contains(actionurl, k) {
|
|
|
- uid, _ := m.GetSession("userId").(string)
|
|
|
+ uid, _ := m.GetSession("mgoUserId").(string)
|
|
|
if NeedBind(uid) {
|
|
|
if mobileReg.MatchString(m.UserAgent()) {
|
|
|
redirectTo := actionurl
|