Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to add/change user password given by file #110

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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