From f8257283b9c07a7e2b255951d083dd4aca9d7940 Mon Sep 17 00:00:00 2001 From: suwings Date: Tue, 3 Apr 2018 08:58:37 +0800 Subject: [PATCH] =?UTF-8?q?Token=20=E5=80=BC=E6=AF=8F=E6=AC=A1=E6=96=AD?= =?UTF-8?q?=E5=BC=80=E5=88=99=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/token.js | 1 + route/user.js | 3 +-- route/websocket.js | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/route/token.js b/route/token.js index 1392227..263310c 100644 --- a/route/token.js +++ b/route/token.js @@ -11,6 +11,7 @@ router.get('/', function (req, res) { //ajax 会受到浏览器跨域限制,姑不能对其进行csrf攻击获取token,尽管它可伪造。 if (req.xhr) { if (!req.session['token']) { + MCSERVER.log('[ Token ]', '用户 ', req.session['username'], ' 请求更新令牌'); //强化 token req.session['token'] = permssion.randomString(6) + UUID.v4().replace(/-/igm, ""); } diff --git a/route/user.js b/route/user.js index 111e59a..cfc1c65 100644 --- a/route/user.js +++ b/route/user.js @@ -14,9 +14,8 @@ const userManager = userCenter(); router.post('/loginout', function (req, res) { permssion.needLogin(req, res, () => { - MCSERVER.log('用户:' + req.session['username'] + '退出'); + MCSERVER.log('[loginout] 用户:' + req.session['username'] + '退出'); req.session.destroy(); - //向前端发送退出 response.returnMsg(res, 'user/logout', 'loginOut'); }, () => { response.returnMsg(res, 'MASTER!', 'Please Login!!! | 请登陆好么?'); diff --git a/route/websocket.js b/route/websocket.js index f24c12f..94ad805 100644 --- a/route/websocket.js +++ b/route/websocket.js @@ -111,7 +111,7 @@ router.ws('/ws', function (ws, req) { }); //response.wsSend(ws, 'ws/res', true); } catch (err) { - MCSERVER.error('WebSocket 请求处理时报错,且下层尚未捕捉', err); + MCSERVER.error('WebSocket 处理此请求出现异常:', err); } }); @@ -121,8 +121,9 @@ router.ws('/ws', function (ws, req) { //释放一些数据 delete varCenter.get('user_token')[token]; - varCenter.get('user_token')[token] = undefined; - delete token; + // varCenter.get('user_token')[token] = undefined; + req.session['token'] = undefined; + req.session.save(); delete WsSession; //释放全局变量