mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-01-12 07:23:21 -05:00
Added function for updateUserImage + bugfix
This commit is contained in:
parent
08636fc02e
commit
f262dd9aa1
74
meshuser.js
74
meshuser.js
@ -1331,43 +1331,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
|
|
||||||
// OK Response
|
// OK Response
|
||||||
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'edituser', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
|
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'edituser', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'updateUserImage':
|
|
||||||
{
|
|
||||||
if (req.session.loginToken != null) break; // Do not allow this command when logged in using a login token
|
|
||||||
|
|
||||||
var uid = user._id;
|
|
||||||
if ((typeof command.userid == 'string') && ((user.siteadmin & SITERIGHT_MANAGEUSERS) != 0)) { uid = command.userid; }
|
|
||||||
|
|
||||||
var chguser = parent.users[uid], flags = 0, change = 0;
|
|
||||||
if (chguser == null) break;
|
|
||||||
if (typeof chguser.flags == 'number') { flags = chguser.flags; }
|
|
||||||
|
|
||||||
if (command.image == 0) {
|
|
||||||
// Delete the image
|
|
||||||
db.Remove('im' + uid);
|
|
||||||
if ((flags & 1) != 0) { flags -= 1; change = 1; }
|
|
||||||
} else if ((typeof command.image == 'string') && (command.image.length < 600000) && ((command.image.startsWith('data:image/png;base64,') || (command.image.startsWith('data:image/jpeg;base64,'))))) {
|
|
||||||
// Save the new image
|
|
||||||
db.Set({ _id: 'im' + uid, image: command.image });
|
|
||||||
if ((flags & 1) == 0) { flags += 1; }
|
|
||||||
change = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the user if needed
|
|
||||||
if (change == 1) {
|
|
||||||
chguser.flags = flags;
|
|
||||||
db.SetUser(chguser);
|
|
||||||
|
|
||||||
// Event the change
|
|
||||||
var targets = ['*', 'server-users', user._id, chguser._id];
|
|
||||||
if (allTargetGroups) { for (var i in allTargetGroups) { targets.push('server-users:' + i); } }
|
|
||||||
var event = { etype: 'user', userid: uid, username: chguser.name, account: parent.CloneSafeUser(chguser), action: 'accountchange', msgid: 66, msgArgs: [chguser.name], msg: 'Account changed: ' + chguser.name, domain: domain.id, accountImageChange: 1 };
|
|
||||||
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
|
|
||||||
parent.parent.DispatchEvent(targets, obj, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'usergroups':
|
case 'usergroups':
|
||||||
@ -5007,6 +4970,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
'servertimelinestats': serverCommandServerTimelineStats,
|
'servertimelinestats': serverCommandServerTimelineStats,
|
||||||
'serverupdate': serverCommandServerUpdate,
|
'serverupdate': serverCommandServerUpdate,
|
||||||
'serverversion': serverCommandServerVersion,
|
'serverversion': serverCommandServerVersion,
|
||||||
|
'updateUserImage': serverCommandUpdateUserImage,
|
||||||
'urlargs': serverCommandUrlArgs,
|
'urlargs': serverCommandUrlArgs,
|
||||||
'users': serverCommandUsers,
|
'users': serverCommandUsers,
|
||||||
'verifyemail': serverCommandVerifyEmail,
|
'verifyemail': serverCommandVerifyEmail,
|
||||||
@ -6099,6 +6063,42 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
parent.parent.getServerTags(function (tags, err) { try { ws.send(JSON.stringify({ action: 'serverversion', tags: tags })); } catch (ex) { } });
|
parent.parent.getServerTags(function (tags, err) { try { ws.send(JSON.stringify({ action: 'serverversion', tags: tags })); } catch (ex) { } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serverCommandUpdateUserImage(command) {
|
||||||
|
if (req.session.loginToken != null) return; // Do not allow this command when logged in using a login token
|
||||||
|
|
||||||
|
var uid = user._id;
|
||||||
|
if ((typeof command.userid == 'string') && ((user.siteadmin & SITERIGHT_MANAGEUSERS) != 0)) { uid = command.userid; }
|
||||||
|
|
||||||
|
var chguser = parent.users[uid], flags = 0, change = 0;
|
||||||
|
if (chguser == null) return;
|
||||||
|
if (typeof chguser.flags == 'number') { flags = chguser.flags; }
|
||||||
|
|
||||||
|
if (command.image == 0) {
|
||||||
|
// Delete the image
|
||||||
|
db.Remove('im' + uid);
|
||||||
|
if ((flags & 1) != 0) { flags -= 1; change = 1; }
|
||||||
|
} else if ((typeof command.image == 'string') && (command.image.length < 600000) && ((command.image.startsWith('data:image/png;base64,') || (command.image.startsWith('data:image/jpeg;base64,'))))) {
|
||||||
|
// Save the new image
|
||||||
|
db.Set({ _id: 'im' + uid, image: command.image });
|
||||||
|
if ((flags & 1) == 0) { flags += 1; }
|
||||||
|
change = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the user if needed
|
||||||
|
if (change == 1) {
|
||||||
|
chguser.flags = flags;
|
||||||
|
db.SetUser(chguser);
|
||||||
|
|
||||||
|
// Event the change
|
||||||
|
var targets = ['*', 'server-users', user._id, chguser._id];
|
||||||
|
var allTargetGroups = chguser.groups;
|
||||||
|
if (allTargetGroups) { for (var i in allTargetGroups) { targets.push('server-users:' + i); } }
|
||||||
|
var event = { etype: 'user', userid: uid, username: chguser.name, account: parent.CloneSafeUser(chguser), action: 'accountchange', msgid: 66, msgArgs: [chguser.name], msg: 'Account changed: ' + chguser.name, domain: domain.id, accountImageChange: 1 };
|
||||||
|
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
|
||||||
|
parent.parent.DispatchEvent(targets, obj, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function serverCommandUrlArgs(command) {
|
function serverCommandUrlArgs(command) {
|
||||||
console.log(req.query);
|
console.log(req.query);
|
||||||
console.log(command.args);
|
console.log(command.args);
|
||||||
|
Loading…
Reference in New Issue
Block a user