--createaccount can now use userid + name.

This commit is contained in:
Ylian Saint-Hilaire 2020-05-26 12:53:35 -07:00
parent 5e6acce776
commit c00e47647b

View File

@ -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);
});