|
|
@@ -27,13 +27,7 @@ RouterUtils.prototype.requireLogin =function(req, res) {
|
|
|
};
|
|
|
|
|
|
RouterUtils.prototype.onApiRequest = function(req, res) {
|
|
|
- this.onRequest(req);
|
|
|
- req.sessionObj = Security.getSessionObj(req.cookies);
|
|
|
- if (req.sessionObj === null) {
|
|
|
- const log = Security.createSession(req);
|
|
|
- res.setHeader("Set-Cookie", Security.SESSION_COOKIE +'='+log.key);
|
|
|
- req.sessionObj = log.data;
|
|
|
- }
|
|
|
+ this.onRequest(req, res);
|
|
|
};
|
|
|
|
|
|
RouterUtils.prototype.onBadRequest =function(res) {
|
|
|
@@ -70,8 +64,14 @@ RouterUtils.prototype.prepareCookie = function(req) {
|
|
|
let arr = ((req.headers?.cookie || "").split(';').map(i => i.split('=', 2))).forEach(i => { req.cookies[i[0].trim()] = decodeURIComponent(i[1]).trim();});
|
|
|
}
|
|
|
|
|
|
-RouterUtils.prototype.onRequest = function(req) {
|
|
|
+RouterUtils.prototype.onRequest = function(req, res) {
|
|
|
this.prepareCookie(req);
|
|
|
+ req.sessionObj = Security.getSessionObj(req.cookies);
|
|
|
+ if (!req.sessionObj) {
|
|
|
+ const log = Security.createSession(req);
|
|
|
+ res.setHeader("Set-Cookie", `${Security.SESSION_COOKIE}=${log.key};Path=/`);
|
|
|
+ req.sessionObj = log.data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
RouterUtils.prototype.readPostBody = function(req, res) {
|