Skip to content
Snippets Groups Projects
Commit 1dee7b77 authored by echicken's avatar echicken :chicken:
Browse files

Reuse the same User instance where applicable, changing number to load a new record.

Dereference User instance when it's no longer needed.
This may help with the old too-many-open-files thing.
NB: web/pages/.examples/More/001-userlist.xjs must be copied to a production location, default would be web/pages/More/001-userlist.xjs, if you want a userlist page.
parent 12c32444
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,7 @@ function setCookie(usr, sessionKey) { ...@@ -48,6 +48,7 @@ function setCookie(usr, sessionKey) {
function validateSession(cookies) { function validateSession(cookies) {
var usr = new User(0);
for (var c in cookies) { for (var c in cookies) {
if (cookies[c].search(/^\d+,\w+$/) < 0) continue; if (cookies[c].search(/^\d+,\w+$/) < 0) continue;
...@@ -55,7 +56,7 @@ function validateSession(cookies) { ...@@ -55,7 +56,7 @@ function validateSession(cookies) {
var cookie = cookies[c].split(','); var cookie = cookies[c].split(',');
try { try {
var usr = new User(cookie[0]); usr.number = cookie[0];
if (usr.number < 1) { if (usr.number < 1) {
throw 'Invalid user number ' + cookie[0] + ' in cookie.'; throw 'Invalid user number ' + cookie[0] + ' in cookie.';
} }
...@@ -70,17 +71,20 @@ function validateSession(cookies) { ...@@ -70,17 +71,20 @@ function validateSession(cookies) {
continue; continue;
} }
authenticate(usr.alias, usr.security.password); var _usr = authenticate(usr.alias, usr.security.password);
_usr = undefined;
setCookie(usr, session.key); setCookie(usr, session.key);
setSessionValue(usr.number, 'ip_address', client.ip_address); setSessionValue(usr.number, 'ip_address', client.ip_address);
break; break;
} }
usr = undefined;
} }
function destroySession(cookies) { function destroySession(cookies) {
var usr = new User(0);
for (var c in cookies) { for (var c in cookies) {
if (cookies[c].search(/^\d+,\w+$/) < 0) continue; if (cookies[c].search(/^\d+,\w+$/) < 0) continue;
...@@ -89,7 +93,7 @@ function destroySession(cookies) { ...@@ -89,7 +93,7 @@ function destroySession(cookies) {
try { try {
var usr = new User(cookie[0]); usr.number = cookie[0];
if(usr.number < 1) { if(usr.number < 1) {
throw 'Invalid user number ' + cookie[0] + ' in cookie.'; throw 'Invalid user number ' + cookie[0] + ' in cookie.';
} }
...@@ -123,6 +127,7 @@ function destroySession(cookies) { ...@@ -123,6 +127,7 @@ function destroySession(cookies) {
} }
} }
usr = undefined;
} }
...@@ -174,6 +179,7 @@ if (user.number === 0) { ...@@ -174,6 +179,7 @@ if (user.number === 0) {
if (gn > 0) { if (gn > 0) {
var gu = new User(gn); var gu = new User(gn);
login(gu.alias, gu.security.password); login(gu.alias, gu.security.password);
gu = undefined;
} else { } else {
// Otherwise just kill the script, for security's sake // Otherwise just kill the script, for security's sake
exit(); exit();
......
...@@ -152,6 +152,7 @@ ...@@ -152,6 +152,7 @@
} }
users.push(copyProperties(usr, {})); users.push(copyProperties(usr, {}));
} }
usr = undefined;
users.sort(sortUsers); users.sort(sortUsers);
return users.slice(offset, offset + pageSize); return users.slice(offset, offset + pageSize);
} }
......
...@@ -19,7 +19,7 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') && ...@@ -19,7 +19,7 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') &&
switch (http_request.query.call[0]) { switch (http_request.query.call[0]) {
case 'node-list': case 'node-list':
var usr = new User(1); var usr = new User(0);
reply = system.node_list.map(function (node) { reply = system.node_list.map(function (node) {
usr.number = node.useron; usr.number = node.useron;
return ({ return ({
...@@ -42,6 +42,7 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') && ...@@ -42,6 +42,7 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') &&
user : usr.alias user : usr.alias
}); });
} }
usr = undefined;
break; break;
case 'send-telegram': case 'send-telegram':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment