|
@@ -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
|