|
@@ -9,6 +9,7 @@ import (
|
|
|
"jy/src/jfw/wx"
|
|
|
"log"
|
|
|
"math/rand"
|
|
|
+ "net/http"
|
|
|
"net/url"
|
|
|
"regexp"
|
|
|
"strconv"
|
|
@@ -621,7 +622,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, true)
|
|
|
+ ok, user, userInfo := FindUserAndCreateSess(f.Request, openid, f.Session(), "pc", true, true)
|
|
|
if ok {
|
|
|
(*user)["shareid"] = shareid
|
|
|
f.SetSession("user", *user)
|
|
@@ -807,27 +808,27 @@ func (m *Front) Wxerr() error {
|
|
|
}
|
|
|
|
|
|
// 查找用户并创建session
|
|
|
-func FindUserAndCreateSess(openid string, sess *httpsession.Session, typ string, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
- return CreateSession(map[string]interface{}{
|
|
|
+func FindUserAndCreateSess(request *http.Request, openid string, sess *httpsession.Session, typ string, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+ return CreateSession(request, map[string]interface{}{
|
|
|
"s_m_openid": openid,
|
|
|
"s_unionid": map[string]interface{}{"$ne": openid}, //处理排除未关注用户点击菜单创建的用户
|
|
|
"i_ispush": 1,
|
|
|
}, sess, typ, flag, isSwitchToBestIdentity)
|
|
|
}
|
|
|
-func FindUserAndCreateSessByBaseUserId(userId int64, sess *httpsession.Session, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
- return CreateSession(map[string]interface{}{
|
|
|
+func FindUserAndCreateSessByBaseUserId(request *http.Request, userId int64, sess *httpsession.Session, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+ return CreateSession(request, map[string]interface{}{
|
|
|
"base_user_id": userId,
|
|
|
}, sess, "pc", flag, isSwitchToBestIdentity)
|
|
|
|
|
|
}
|
|
|
|
|
|
-func FindUserAndCreateSessById(userId primitive.ObjectID, sess *httpsession.Session, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
- return CreateSession(map[string]interface{}{
|
|
|
+func FindUserAndCreateSessById(request *http.Request, userId primitive.ObjectID, sess *httpsession.Session, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+ return CreateSession(request, map[string]interface{}{
|
|
|
"_id": userId,
|
|
|
}, sess, "pc", flag, isSwitchToBestIdentity)
|
|
|
}
|
|
|
|
|
|
-func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ string, flag, isSwitchToBestIdentity bool) (bool, *map[string]interface{}, map[string]interface{}) {
|
|
|
+func CreateSession(request *http.Request, 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
|
|
|
}
|
|
@@ -836,6 +837,9 @@ func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ stri
|
|
|
return false, nil, nil
|
|
|
}
|
|
|
userid := util.ObjToString(sessionVal["userId"])
|
|
|
+ if request != nil && strings.Contains(request.UserAgent(), "JianyuDebug") {
|
|
|
+ flag = true
|
|
|
+ }
|
|
|
if pcSessionFlag, ok := config.Sysconfig["pcSessionFlag"].(bool); pcSessionFlag && ok && flag {
|
|
|
//无限制登陆用户
|
|
|
if util.IntAll(sessionVal["i_unlimited"]) <= 0 {
|
|
@@ -896,18 +900,18 @@ func (m *Front) Sess(ostr string) error {
|
|
|
identity = config.Middleground.UserCenter.IdentityByPositionId(util.Int64All(userFlag))
|
|
|
}
|
|
|
if identity != nil {
|
|
|
- ok, _, _ = FindUserAndCreateSessByBaseUserId(identity.UserId, m.Session(), false, false)
|
|
|
+ ok, _, _ = FindUserAndCreateSessByBaseUserId(m.Request, identity.UserId, m.Session(), false, false)
|
|
|
}
|
|
|
} else {
|
|
|
hasIdentity := false
|
|
|
if str[1] == "_id" {
|
|
|
- if ok, _, _ = FindUserAndCreateSessById(mgdb.StringTOBsonId(userFlag), m.Session(), false, !hasIdentity); ok {
|
|
|
+ if ok, _, _ = FindUserAndCreateSessById(m.Request, mgdb.StringTOBsonId(userFlag), m.Session(), false, !hasIdentity); ok {
|
|
|
hasIdentity = true
|
|
|
}
|
|
|
} else {
|
|
|
//P387用户身份及搜索模式优化-微信公众号点击菜单重新获取上次身份
|
|
|
if userFlag != "" {
|
|
|
- if ok, _, _ = FindUserAndCreateSess(userFlag, m.Session(), "wx", false, !hasIdentity); ok {
|
|
|
+ if ok, _, _ = FindUserAndCreateSess(m.Request, userFlag, m.Session(), "wx", false, !hasIdentity); ok {
|
|
|
hasIdentity = true
|
|
|
}
|
|
|
}
|