Factorize authcookie

Noah Zalev committed Dec 7, 2021 at 21:51 UTC c9462811fc86995932ca958c8f0eadb33609c434
1 file changed +11 -12
meshuser.js
+11 -12
@@ -676,18 +676,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
676
677 // TODO: Send the message of user sessions connected to other servers.
678
679 - break;
680 - }
681 - case 'authcookie':
682 - {
683 - // Renew the authentication cookie
684 - try {
685 - ws.send(JSON.stringify({
686 - action: 'authcookie',
687 - cookie: parent.parent.encodeCookie({ userid: user._id, domainid: domain.id, ip: req.clientIp }, parent.parent.loginCookieEncryptionKey),
688 - rcookie: parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey)
689 - }));
690 - } catch (ex) { }
679 break;
680 }
681 case 'logincookie':
@@ -5555,6 +5543,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5543 'adduser': serverCommandAddUser,
5544 'adduserbatch': serverCommandAddUserBatch,
5545 'addusertousergroup': serverCommandAddUserToUserGroup,
5546 + 'authcookie': serverCommandAuthCookie,
5547 'files': serverCommandFiles,
5548 'getnetworkinfo': serverCommandGetNetworkInfo,
5549 'getsysinfo': serverCommandGetSysInfo,
@@ -5916,6 +5905,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5905 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'addusertousergroup', responseid: command.responseid, result: 'ok', added: addedCount, failed: failCount })); } catch (ex) { } }
5906 }
5907
5908 + function serverCommandAuthCookie(command) {
5909 + try {
5910 + ws.send(JSON.stringify({
5911 + action: 'authcookie',
5912 + cookie: parent.parent.encodeCookie({ userid: user._id, domainid: domain.id, ip: req.clientIp }, parent.parent.loginCookieEncryptionKey),
5913 + rcookie: parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey)
5914 + }));
5915 + } catch (ex) { }
5916 + }
5917 +
5918 function serverCommandFiles(command) {
5919 // Send the full list of server files to the browser app
5920 updateUserFiles(user, ws, domain);