Ver código fonte

Merge branch 'feature/v4.8.25_wky' of qmx/jy into feature/v4.8.25

wangkaiyue 2 anos atrás
pai
commit
19650ea9d0

+ 4 - 97
src/jfw/modules/app/src/app/front/login.go

@@ -15,7 +15,6 @@ import (
 	utils "jy/src/jfw/modules/app/src/app/jyutil"
 
 	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"
@@ -29,7 +28,6 @@ import (
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 	"github.com/dchest/captcha"
 	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 // UserSign 签名
@@ -309,7 +307,7 @@ func (l *Login) Sess(ostr string) error {
 				return l.Redirect("/jyapp/free/mob/err")
 			}
 			if sessVal["userId"] == nil {
-				if createSession(l.Session(), fmt.Sprint(identity.UserId), 3, l.ResponseWriter, false) {
+				if jy.JyAppCreateSession(mongodb, l.Session(), fmt.Sprint(identity.UserId), 3, l.ResponseWriter, false, config.Middleground, qutil.ObjToString(config.Sysconfig["appPushServiceRpc"]), qutil.IntAll(config.Sysconfig["criticality"])) {
 					hasSession = true
 				} else {
 					log.Println("创建session失败", str)
@@ -331,7 +329,7 @@ func (l *Login) Sess(ostr string) error {
 						loginType = 1
 					}
 				}
-				if createSession(l.Session(), loginId, loginType, l.ResponseWriter, true) {
+				if jy.JyAppCreateSession(mongodb, l.Session(), loginId, loginType, l.ResponseWriter, true, config.Middleground, qutil.ObjToString(config.Sysconfig["appPushServiceRpc"]), qutil.IntAll(config.Sysconfig["criticality"])) {
 					hasSession = true
 					if identity := config.Middleground.UserCenter.IdentityByUserId(qutil.Int64All(l.GetSession("base_user_id"))); identity != nil {
 						hasSession = hasSession && NewIdentityInfo(identity).Switch(l.Session(), &public.MQFW)
@@ -1053,97 +1051,6 @@ func findWxExistsId(phoneNum string) interface{} {
 	return nil
 }
 
-/*
- * 创建session
- * loginType 0 _id 1 s_phone 2 a_m_openid
- */
-func createSession(s *httpsession.Session, loginId string, loginType int, rw http.ResponseWriter, isSwitchToBestIdentity bool) bool {
-	if loginId == "" {
-		return false
-	}
-	query := map[string]interface{}{
-		"i_appid": 2,
-	}
-	switch loginType {
-	case 0: //_id登录
-		query["_id"], _ = primitive.ObjectIDFromHex(loginId)
-		break
-	case 1: //s_phone登录
-		query["s_phone"] = loginId
-		break
-	case 2: //a_m_openid登录
-		query["a_m_openid"] = loginId
-		break
-	case 3: //base_user_id登录
-		query["base_user_id"] = qutil.Int64All(loginId)
-		break
-	default:
-		return false
-	}
-	data, ok := mongodb.FindOneByField("user", query, `{"s_m_openid":1,"s_phone":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"s_headimageurl":1,"s_phone":1,"s_nickname":1,"s_appversion":1,"i_unlimited":1,"s_jyname":1,"base_user_id":1}`)
-	if !ok || data == nil || len(*data) == 0 {
-		return false
-	}
-	person := *data
-	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)
-		sessVal["s_phone"] = phone
-		phone = string(phone[0:3]) + "****" + string(phone[len(phone)-4:])
-		sessVal["s_nickname"] = phone
-	}
-	if qutil.ObjToString(person["s_m_phone"]) != "" {
-		s_m_phone := person["s_m_phone"].(string)
-		sessVal["s_m_phone"] = s_m_phone
-	}
-	if qutil.ObjToString(person["s_nickname"]) != "" {
-		sessVal["app_name"] = person["s_nickname"]
-	}
-	// 剑鱼昵称
-	if qutil.ObjToString(person["s_jyname"]) != "" {
-		sessVal["s_jyname"] = person["s_jyname"]
-	}
-	s.SetMultiple(sessVal)
-	if isSwitchToBestIdentity {
-		SwitchToBest(qutil.Int64All(sessVal["base_user_id"]), s, config.Middleground, &public.MQFW, true)
-	}
-	//cookie
-	maxAge := int(time.Hour * 72 / time.Second) //3天,单位秒
-	expires := time.Now().Add(72 * time.Hour)
-	simpleuid := encrypt.SE.EncodeString(BsonIdToSId(person["_id"]))
-	c := &http.Cookie{
-		Name:     "ud_safe",
-		Value:    simpleuid,
-		Path:     "/",
-		HttpOnly: false,
-		MaxAge:   maxAge,
-		Expires:  expires,
-	}
-	http.SetCookie(rw, c)
-	//多账号登陆用户
-	i_unlimited := qutil.IntAll(person["i_unlimited"])
-	if i_unlimited > 0 {
-		uid := BsonIdToSId(person["_id"])
-		jy.PutLoginSess(mongodb, qutil.ObjToString(config.Sysconfig["appPushServiceRpc"]), fmt.Sprint(s.Id()), uid, qutil.IntAll(config.Sysconfig["criticality"]), i_unlimited)
-		redis.Put("other", fmt.Sprintf("app_%s", fmt.Sprint(s.Id())), &jy.AppLoginPush{
-			JgPushId:    qutil.ObjToString(person["s_jpushid"]),
-			OtherPushId: qutil.ObjToString(person["s_opushid"]),
-			PhoneType:   qutil.ObjToString(person["s_appponetype"]),
-		}, 86400*30)
-	}
-	return true
-}
-
 // 清除session
 func ClearSession(s *httpsession.Session) {
 	s.Clear()
@@ -1258,7 +1165,7 @@ func afterLogin(user map[string]interface{}, session *httpsession.Session, rid,
 			jyutil.UnLoginPush.DeleteBuff(rid)
 		}
 	}()
-	createSession(session, userid, 0, rw, true)
+	jy.JyAppCreateSession(mongodb, session, userid, 0, rw, true, config.Middleground, qutil.ObjToString(config.Sysconfig["appPushServiceRpc"]), qutil.IntAll(config.Sysconfig["criticality"]))
 	return createSign(userid, rid, "登录后", session)
 }
 
@@ -1282,7 +1189,7 @@ func autoLogin(sign, from string, session *httpsession.Session, rw http.Response
 	// 		return -3
 	// 	}
 	// }
-	if createSession(session, u.UserId, 0, rw, true) {
+	if jy.JyAppCreateSession(mongodb, session, u.UserId, 0, rw, true, config.Middleground, qutil.ObjToString(config.Sysconfig["appPushServiceRpc"]), qutil.IntAll(config.Sysconfig["criticality"])) {
 		return 1
 	}
 	return 0

+ 1 - 1
src/jfw/modules/app/src/go.mod

@@ -5,7 +5,7 @@ go 1.18
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230517064222-e0bdfc8ee0e8
 	app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545
-	app.yhyue.com/moapp/jypkg v0.0.0-20230517064346-54ec66481628
+	app.yhyue.com/moapp/jypkg v0.0.0-20230530062043-31fb8812489b
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.13
 	github.com/SKatiyar/qr v0.0.0-20151201054752-25b6bdf44e67
 	github.com/dchest/captcha v1.0.0

+ 2 - 2
src/jfw/modules/app/src/go.sum

@@ -9,8 +9,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20230517064222-e0bdfc8ee0e8 h1:0ukFbYC7yRkFvRs
 app.yhyue.com/moapp/jybase v0.0.0-20230517064222-e0bdfc8ee0e8/go.mod h1:zB47XTeJvpcbtBRYgkQuxOICWNexiZfbUO+7aUf6mNs=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545 h1:+Lak4m1zgsigQloOsvp8AJ+0XeX/+PGp9QP550xlbBQ=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545/go.mod h1:uFrsdUBFbETiJlEmr4PtJWPsZlUpPj2bHQRhryu6ggk=
-app.yhyue.com/moapp/jypkg v0.0.0-20230517064346-54ec66481628 h1:JrlY3EGZv+sNffZSRXNFSCYtudPXKD3Dks3970vqJ40=
-app.yhyue.com/moapp/jypkg v0.0.0-20230517064346-54ec66481628/go.mod h1:zpXgWwV+/gwZBV24bffc4OhptUMT5zEVxwq1ENf0OYQ=
+app.yhyue.com/moapp/jypkg v0.0.0-20230530062043-31fb8812489b h1:04NNjxzwLCIjC+QInlwtbDfIxDZyYe4oaBe9qf6ivdw=
+app.yhyue.com/moapp/jypkg v0.0.0-20230530062043-31fb8812489b/go.mod h1:Ize93SJEPkBR0Tz8PM2KTJK3bpzlD/qp1JwJ4kdmlss=
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae h1:6rDDaz6yxvE8viTSzEBwKYOFWq14TMfuBivSazUZMz4=
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae/go.mod h1:b0zZHev3gmJao1Fo+2Z2KPVjsuLOJVvVxf+kCnu9WkA=
 bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230214091519-89a98c01ab0e h1:h+VEI3o1qC0jeCzkFGTrLI4f27cfa/W/y+0sXokWMgE=