Skip to content

Commit

Permalink
Possibility to add/change user password given by file
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertfisch committed Sep 21, 2021
1 parent 38a5b24 commit 4883c25
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions admin
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ var LOCAL_AUTH_FILE = path.resolve(process.env.LOCAL_AUTH_FILE || './.users.json

console.log('Using local auth file: ', LOCAL_AUTH_FILE);

function addUser(options) {
function checkOptions(options) {
if (!options.username) exit('missing --username');
if (!options.password) exit('missing --password');
if (!options.password) {
if (!options.passwordFile) {
exit('missing --password or --password-file');
}
var password = safe.require(path.resolve(options.passwordFile));
if (!password) {
exit('No password found or password file invalid');
}
options.password = password;
}
if (!options.displayName) exit('missing --display-name');
}

function addUser(options) {
checkOptions(options);

var users = safe.require(LOCAL_AUTH_FILE);
if (!users) users = {};
Expand All @@ -39,9 +52,7 @@ function addUser(options) {
}

function editUser(options) {
if (!options.username) exit('missing --username');
if (!options.password) exit('missing --password');
if (!options.displayName) exit('missing --display-name');
checkOptions(options);

var users = safe.require(LOCAL_AUTH_FILE);
if (!users) users = {};
Expand Down Expand Up @@ -87,13 +98,15 @@ program.command('user-add')
.description('Add local user')
.option('-u --username <username>', 'New username')
.option('-p --password <password>', 'New password')
.option('--password-file <fileName>', 'Password file containing new password in quotes')
.option('--display-name <displayName>', 'New display name')
.action(addUser);

program.command('user-edit')
.description('Edit local user')
.option('-u --username <username>', 'Username')
.option('-p --password <password>', 'New password')
.option('--password-file <fileName>', 'Password file containing new password in quotes')
.option('--display-name <displayName>', 'New display name')
.action(editUser);

Expand Down

0 comments on commit 4883c25

Please sign in to comment.