oputil.js user activate <name> will now unlock accounts

This commit is contained in:
Bryan Ashby 2018-11-23 12:02:41 -07:00
parent a4823c0c4a
commit f45e785da1
1 changed files with 26 additions and 23 deletions

View File

@ -8,25 +8,13 @@ const argv = require('./oputil_common.js').argv;
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases; const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
const getHelpFor = require('./oputil_help.js').getHelpFor; const getHelpFor = require('./oputil_help.js').getHelpFor;
const Errors = require('../enig_error.js').Errors; const Errors = require('../enig_error.js').Errors;
const UserProps = require('../user_property.js');
const async = require('async'); const async = require('async');
const _ = require('lodash'); const _ = require('lodash');
exports.handleUserCommand = handleUserCommand; exports.handleUserCommand = handleUserCommand;
function getUser(userName, cb) {
const User = require('../../core/user.js');
User.getUserIdAndName(userName, (err, userId) => {
if(err) {
process.exitCode = ExitCodes.BAD_ARGS;
return cb(err);
}
const u = new User();
u.userId = userId;
return cb(null, u);
});
}
function initAndGetUser(userName, cb) { function initAndGetUser(userName, cb) {
async.waterfall( async.waterfall(
[ [
@ -34,12 +22,12 @@ function initAndGetUser(userName, cb) {
initConfigAndDatabases(callback); initConfigAndDatabases(callback);
}, },
function getUserObject(callback) { function getUserObject(callback) {
getUser(userName, (err, user) => { const User = require('../../core/user.js');
User.getUserIdAndName(userName, (err, userId) => {
if(err) { if(err) {
process.exitCode = ExitCodes.BAD_ARGS;
return callback(err); return callback(err);
} }
return callback(null, user); return User.getUser(userId, callback);
}); });
} }
], ],
@ -64,14 +52,29 @@ function setAccountStatus(user, status) {
}[status]; }[status];
const statusDesc = _.invert(AccountStatus)[status]; const statusDesc = _.invert(AccountStatus)[status];
user.persistProperty('account_status', status, err => {
if(err) { async.series(
process.exitCode = ExitCodes.ERROR; [
console.error(err.message); (callback) => {
} else { return user.persistProperty(UserProps.AccountStatus, status, callback);
console.info(`User status set to ${statusDesc}`); },
(callback) => {
if(AccountStatus.active !== status) {
return callback(null);
}
return user.unlockAccount(callback);
}
],
err => {
if(err) {
process.exitCode = ExitCodes.ERROR;
console.error(err.message);
} else {
console.info(`User status set to ${statusDesc}`);
}
} }
}); );
} }
function setUserPassword(user) { function setUserPassword(user) {