|
@@ -15,11 +15,12 @@ import (
|
|
|
|
|
|
qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
-
|
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
qrpc "app.yhyue.com/moapp/jybase/rpc"
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ . "app.yhyue.com/moapp/jypkg/identity"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
|
|
|
"app.yhyue.com/moapp/jybase/usercenter"
|
|
|
"app.yhyue.com/moapp/jypkg/public"
|
|
@@ -278,21 +279,45 @@ func (l *Login) Sess(ostr string) error {
|
|
|
str := strings.Split(sewx.DecodeString(strs[0]), ",")
|
|
|
if len(str) == 4 {
|
|
|
hasSession := false
|
|
|
- if l.GetSession("userId") != nil {
|
|
|
+ if l.GetSession("positionId") != nil {
|
|
|
hasSession = true
|
|
|
} else {
|
|
|
- loginType := 0
|
|
|
loginId := str[0]
|
|
|
- if str[1] == "uid" {
|
|
|
- loginType = 2
|
|
|
- if phoneReg.MatchString(loginId) {
|
|
|
- loginType = 1
|
|
|
+ var identity *pb.Identity
|
|
|
+ if str[1] == "userId" || str[1] == "entUserId" || str[1] == "positionId" {
|
|
|
+ if str[1] == "userId" {
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByUserId(util.Int64All(loginId))
|
|
|
+ } else if str[1] == "entUserId" {
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByEntUserId(util.Int64All(loginId))
|
|
|
+ } else if str[1] == "positionId" {
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByPositionId(util.Int64All(loginId))
|
|
|
+ }
|
|
|
+ if identity != nil {
|
|
|
+ if createSession(l.Session(), nil, fmt.Sprint(identity.UserId), 3, l.ResponseWriter) {
|
|
|
+ hasSession = true
|
|
|
+ } else {
|
|
|
+ log.Println("创建session失败", str)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ loginType := 0
|
|
|
+ if str[1] == "uid" {
|
|
|
+ loginType = 2
|
|
|
+ if phoneReg.MatchString(loginId) {
|
|
|
+ loginType = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if createSession(l.Session(), nil, loginId, loginType, l.ResponseWriter) {
|
|
|
+ hasSession = true
|
|
|
+ identity = config.Middleground.UserCenter.IdentityByUserId(util.Int64All(m.GetSession("base_user_id")))
|
|
|
+ } else {
|
|
|
+ log.Println("创建session失败", str)
|
|
|
}
|
|
|
}
|
|
|
- if createSession(l.Session(), nil, loginId, loginType, l.ResponseWriter) {
|
|
|
- hasSession = true
|
|
|
+ if identity != nil {
|
|
|
+ hasSession = hasSession && NewIdentityInfo(identity).Switch(m.Session())
|
|
|
} else {
|
|
|
- log.Println("创建session失败", loginId)
|
|
|
+ log.Println("获取用户身份信息失败", str)
|
|
|
}
|
|
|
}
|
|
|
if hasSession {
|
|
@@ -303,21 +328,17 @@ func (l *Login) Sess(ostr string) error {
|
|
|
}
|
|
|
//切换企业身份
|
|
|
if len(strs) > 2 {
|
|
|
- var entParams []string
|
|
|
+ var entUserId int64
|
|
|
if strings.HasPrefix(strs[2], "V20221215-") {
|
|
|
- entParams = strings.Split(sewx.Decode4HexByCheck(strings.TrimPrefix(strs[2], "V20221215-")), "_")
|
|
|
+ entParams := strings.Split(sewx.Decode4HexByCheck(strings.TrimPrefix(strs[2], "V20221215-")), "_")
|
|
|
+ entUserId := qutil.Int64All(entParams[1])
|
|
|
} else {
|
|
|
- entParams = strings.Split(sewx.DecodeString(strs[2]), "_")
|
|
|
- ents := public.Mysql.SelectBySql(`select name from entniche_info where id=?`, qutil.Int64All(entParams[0]))
|
|
|
- if ents != nil && len(*ents) > 0 {
|
|
|
- entParams[2] = qutil.ObjToString((*ents)[0]["name"])
|
|
|
- }
|
|
|
+ entParams := strings.Split(sewx.DecodeString(strs[2]), "_")
|
|
|
+ entUserId := qutil.Int64All(entParams[1])
|
|
|
+ }
|
|
|
+ if identity := config.Middleground.UserCenter.IdentityByEntUserId(entUserId); identity != nil {
|
|
|
+ NewIdentityInfo(identity).Switch(m.Session())
|
|
|
}
|
|
|
- l.Session().SetMultiple(map[string]interface{}{
|
|
|
- "entId": qutil.Int64All(entParams[0]),
|
|
|
- "entUserId": qutil.Int64All(entParams[1]),
|
|
|
- "entName": qutil.ObjToString(entParams[2]),
|
|
|
- })
|
|
|
}
|
|
|
} else {
|
|
|
actionurl = qutil.ObjToString(urlMap[str[3]])
|
|
@@ -985,7 +1006,6 @@ func createSession(s *httpsession.Session, person map[string]interface{}, loginI
|
|
|
query := map[string]interface{}{
|
|
|
"i_appid": 2,
|
|
|
}
|
|
|
- log.Println("~~~~~~~``", loginType, loginId)
|
|
|
switch loginType {
|
|
|
case 0: //_id登录
|
|
|
query["_id"], _ = primitive.ObjectIDFromHex(loginId)
|
|
@@ -996,6 +1016,9 @@ func createSession(s *httpsession.Session, person map[string]interface{}, loginI
|
|
|
case 2: //a_m_openid登录
|
|
|
query["a_m_openid"] = loginId
|
|
|
break
|
|
|
+ case 3: //a_m_openid登录
|
|
|
+ query["base_user_id"] = qutil.Int64All(loginId)
|
|
|
+ break
|
|
|
default:
|
|
|
return false
|
|
|
}
|
|
@@ -1019,61 +1042,35 @@ func createSession(s *httpsession.Session, person map[string]interface{}, loginI
|
|
|
}
|
|
|
person = *data
|
|
|
}
|
|
|
- s.Set("userId", BsonIdToSId(person["_id"]))
|
|
|
- s.Set("s_jpushid", person["s_jpushid"])
|
|
|
- s.Set("s_m_openid", person["s_m_openid"])
|
|
|
- s.Set("s_opushid", person["s_opushid"])
|
|
|
- s.Set("s_appponetype", person["s_appponetype"])
|
|
|
- s.Set("s_appversion", person["s_appversion"])
|
|
|
- s.Set("s_headimageurl", strings.Replace(qutil.ObjToString(person["s_headimageurl"]), "http://", "https://", 1))
|
|
|
- s.Set("i_unlimited", qutil.IntAll(person["i_unlimited"]))
|
|
|
- if base_userid := qutil.IntAllDef(person["base_user_id"], 0); base_userid != 0 {
|
|
|
- s.Set("base_user_id", base_userid)
|
|
|
- //
|
|
|
- //
|
|
|
- uid := BsonIdToSId(person["_id"])
|
|
|
- identity := usercenter.GetUserIdentity(qutil.ObjToString(config.Sysconfig["userCenterApi"]), uid, int64(base_userid), 0, &http.Cookie{})
|
|
|
- if identity != nil {
|
|
|
- if identity.PersonId > 0 {
|
|
|
- s.Set("personId", identity.PersonId)
|
|
|
- }
|
|
|
- if identity.UserName != "" {
|
|
|
- s.Set("personId", identity.PersonId)
|
|
|
- }
|
|
|
- if identity.UserAccountId > 0 {
|
|
|
- s.Set("userAccountId", identity.UserAccountId)
|
|
|
- }
|
|
|
- if identity.EntAccountId > 0 {
|
|
|
- s.Set("entAccountId", identity.EntAccountId)
|
|
|
- }
|
|
|
- if identity.EntUserAccountId > 0 {
|
|
|
- s.Set("entUserAccountId", identity.EntUserAccountId)
|
|
|
- }
|
|
|
- if identity.UserPositionId > 0 {
|
|
|
- s.Set("userPositionId", identity.UserPositionId)
|
|
|
- }
|
|
|
- if identity.EntUserPositionId > 0 {
|
|
|
- s.Set("entUserPositionId", identity.EntUserPositionId)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ sessVal := map[string]interface{}{}
|
|
|
+ sessVal["userId"] = BsonIdToSId(person["_id"])
|
|
|
+ sessVal["mgoUserId"] = sessVal["userId"]
|
|
|
+ sessVal["s_jpushid"] = person["s_jpushid"]
|
|
|
+ sessVal["s_m_openid"] = person["s_m_openid"]
|
|
|
+ sessVal["s_opushid"] = person["s_opushid"]
|
|
|
+ sessVal["s_appponetype"] = person["s_appponetype"]
|
|
|
+ sessVal["s_appversion"] = person["s_appversion"]
|
|
|
+ sessVal["s_headimageurl"] = strings.Replace(qutil.ObjToString(person["s_headimageurl"]), "http://", "https://", 1)
|
|
|
+ sessVal["i_unlimited"] = qutil.IntAll(person["i_unlimited"])
|
|
|
+ sessVal["base_user_id"] = qutil.IntAll(person["base_user_id"])
|
|
|
if qutil.ObjToString(person["s_phone"]) != "" {
|
|
|
phone := person["s_phone"].(string)
|
|
|
- s.Set("s_phone", phone)
|
|
|
+ sessVal["s_phone"] = phone
|
|
|
phone = string(phone[0:3]) + "****" + string(phone[len(phone)-4:])
|
|
|
- s.Set("s_nickname", phone)
|
|
|
+ sessVal["s_nickname"] = phone
|
|
|
}
|
|
|
if qutil.ObjToString(person["s_m_phone"]) != "" {
|
|
|
s_m_phone := person["s_m_phone"].(string)
|
|
|
- s.Set("s_m_phone", s_m_phone)
|
|
|
+ sessVal["s_m_phone"] = s_m_phone
|
|
|
}
|
|
|
if qutil.ObjToString(person["s_nickname"]) != "" {
|
|
|
- s.Set("app_name", person["s_nickname"])
|
|
|
+ sessVal["app_name"] = person["s_nickname"]
|
|
|
}
|
|
|
// 剑鱼昵称
|
|
|
if qutil.ObjToString(person["s_jyname"]) != "" {
|
|
|
- s.Set("s_jyname", person["s_jyname"])
|
|
|
+ sessVal["s_jyname"] = person["s_jyname"]
|
|
|
}
|
|
|
+ s.SetMultiple(sessVal)
|
|
|
//cookie
|
|
|
maxAge := int(time.Hour * 72 / time.Second) //3天,单位秒
|
|
|
expires := time.Now().Add(72 * time.Hour)
|