Forráskód Böngészése

feat:微信扫码登录 选择下次自动登录

wangshan 2 éve
szülő
commit
614433357b
2 módosított fájl, 23 hozzáadás és 6 törlés
  1. 10 6
      src/jfw/front/websocket.go
  2. 13 0
      src/web/staticres/js/login.js

+ 10 - 6
src/jfw/front/websocket.go

@@ -136,15 +136,19 @@ func GetWsByCode(param []string) bool {
 		if infoData != nil {
 			baseUserId := qutil.Int64All(session.Get("base_user_id"))
 			if ok, err := redis.Exists("newother", fmt.Sprintf(jyutil.KeepLoginTimeKey, src)); ok && err == nil && baseUserId > 0 {
-				infoData[jyutil.KeepLoginCookieName] = encrypt.SE.EncodeString(strconv.FormatInt(baseUserId, 10))
+				infoData["cValue"] = encrypt.SE.EncodeString(strconv.FormatInt(baseUserId, 10))
+				infoData["cName"] = jyutil.KeepLoginCookieName
 				expiresHour := qutil.IntAll(Sysconfig["setSessionTimeout"])
 				expires := time.Now().Add(time.Duration(expiresHour) * time.Hour)
-				infoData["expires"] = expires
+				infoData["expires"] = expires.Format("2006-01-02 15:04:05")
 				//往cookie加入标识 保证用户登录状态延期
-				//if ok := redis.Del("newother", fmt.Sprintf(jyutil.KeepLoginTimeKey, src)); !ok {
-				//	log.Println(fmt.Sprintf("%d 清除用户登录延期标识 异常", baseUserId))
-				//}
-				//jyutil.SetCookieValueForAutoLogin(wss.Conn.W, baseUserId)
+				if ok := redis.Del("newother", fmt.Sprintf(jyutil.KeepLoginTimeKey, src)); !ok {
+					log.Println(fmt.Sprintf("%d 清除用户登录延期标识 异常", baseUserId))
+				}
+				//
+				//收到webSocket消息后,您无法设置cookie.一旦建立了webSocket连接,它就是一个开放的TCP套接字,协议不再是http,因此没有内置的方式来交换cookie.
+				//jyutil.SetCookieValueForAutoLogin(wss.Conn.W, baseUserId)  不可用
+				//您可以将自己的webSocket消息发送回客户端,告知它设置cookie,然后在客户端中侦听该消息,当它收到该消息时,它可以在浏览器中设置cookie.
 			}
 		}
 		if wss.Conn == nil {

+ 13 - 0
src/web/staticres/js/login.js

@@ -759,6 +759,15 @@ var afterSignoutClearCookit = function(){
 	}
 }
 
+var afterLoginSetCookit = function(name,value,time){
+	let expires = new Date(time)
+	try{
+		$.cookie(name,value,{expires:expires.toGMTString(),path:"/",domain:document.domain.replace(/[^.]+/,"")});
+	}catch(e){
+		document.cookie = name+"="+value+";expires="+expires.toGMTString()+";path=/;domain="+document.domain.replace(/[^.]+/,"");
+	}
+}
+
 //查看用户是否已经登录
 var haslogin = function(num,kyorpn,url){
 	mynum = num;//页面logid
@@ -1837,6 +1846,10 @@ function openLoginDig(type) {
       var injectLogic = logic
       logic = function (data, num) {
         if (data.result === 'ok') {
+        	//判断是否需要设置cookie 
+			if(data.cValue){
+				afterLoginSetCookit(data.cName,data.cValue,data.expires)
+			}
           // 检查是否需要新窗口打开<新用户兴趣偏好设置页面>
           checkNeedGoNewUserSettingPage()
           if (needToWork) {