|
@@ -0,0 +1,106 @@
|
|
|
+package jy
|
|
|
+
|
|
|
+import (
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jypkg/identity"
|
|
|
+ "app.yhyue.com/moapp/jypkg/middleground"
|
|
|
+ "app.yhyue.com/moapp/jypkg/public"
|
|
|
+ "fmt"
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// JyAppCreateSession app登陆创建session公共方法
|
|
|
+// copy from app program
|
|
|
+func JyAppCreateSession(mdb mongodb.MongodbSim, s *httpsession.Session, loginId string, loginType int, rw http.ResponseWriter, isSwitchToBestIdentity bool, mgd *middleground.Middleground, appPushServiceRpc string, criticality int) 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 := mdb.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"] = mongodb.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 && mgd != nil {
|
|
|
+ identity.SwitchToBest(qutil.Int64All(sessVal["base_user_id"]), s, mgd, &public.MQFW, true)
|
|
|
+ }
|
|
|
+ //cookie
|
|
|
+ maxAge := int(time.Hour * 72 / time.Second) //3天,单位秒
|
|
|
+ expires := time.Now().Add(72 * time.Hour)
|
|
|
+ simpleuid := encrypt.SE.EncodeString(mongodb.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 && appPushServiceRpc != "" {
|
|
|
+ uid := mongodb.BsonIdToSId(person["_id"])
|
|
|
+ PutLoginSess(mdb, appPushServiceRpc, fmt.Sprint(s.Id()), uid, criticality, i_unlimited)
|
|
|
+ redis.Put("other", fmt.Sprintf("app_%s", fmt.Sprint(s.Id())), &AppLoginPush{
|
|
|
+ JgPushId: qutil.ObjToString(person["s_jpushid"]),
|
|
|
+ OtherPushId: qutil.ObjToString(person["s_opushid"]),
|
|
|
+ PhoneType: qutil.ObjToString(person["s_appponetype"]),
|
|
|
+ }, 86400*30)
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|