From c00e47647b872ab32e1a7a01a639a8a633e2b819 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 26 May 2020 12:53:35 -0700 Subject: [PATCH] --createaccount can now use userid + name. --- meshcentral.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index 984237d2..e7d1cb22 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -673,13 +673,13 @@ function CreateMeshCentralServer(config, args) { if (obj.args.recordencryptionrecode) { obj.db.performRecordEncryptionRecode(function (count) { console.log('Re-encoded ' + count + ' record(s).'); process.exit(); }); return; } if (obj.args.dbstats) { obj.db.getDbStats(function (stats) { console.log(stats); process.exit(); }); return; } if (obj.args.createaccount) { // Create a new user account - if ((typeof obj.args.createaccount != 'string') || (obj.args.pass == null) || (obj.args.pass == '') || (obj.args.createaccount.indexOf(' ') >= 0)) { console.log("Usage: --createaccount [userid] --pass [password] --domain (domain) --email (email)."); process.exit(); return; } + if ((typeof obj.args.createaccount != 'string') || (obj.args.pass == null) || (obj.args.pass == '') || (obj.args.createaccount.indexOf(' ') >= 0) || (obj.args.createaccount.indexOf('/') >= 0)) { console.log("Usage: --createaccount [userid] --pass [password] --domain (domain) --email (email) --name (name)."); process.exit(); return; } var userid = 'user/' + (obj.args.domain ? obj.args.domain : '') + '/' + obj.args.createaccount.toLowerCase(), domainid = obj.args.domain ? obj.args.domain : ''; obj.db.Get(userid, function (err, docs) { if (err != null) { console.log("Database error: " + err); process.exit(); return; } if ((docs != null) && (docs.length != 0)) { console.log('User already exists.'); process.exit(); return; } if ((domainid != '') && ((config.domains == null) || (config.domains[domainid] == null))) { console.log("Invalid domain."); process.exit(); return; } - var user = { _id: userid, type: 'user', name: obj.args.createaccount, domain: domainid, creation: Math.floor(Date.now() / 1000), links: {} }; + var user = { _id: userid, type: 'user', name: (typeof obj.args.name == 'string')?obj.args.name:obj.args.createaccount, domain: domainid, creation: Math.floor(Date.now() / 1000), links: {} }; if (typeof obj.args.email == 'string') { user.email = obj.args.email; user.emailVerified = true; } require('./pass').hash(obj.args.pass, function (err, salt, hash, tag) { if (err) { console.log("Unable create account password: " + err); process.exit(); return; } user.salt = salt; user.hash = hash; obj.db.Set(user, function () { console.log("Done."); process.exit(); return; }); }, 0); });