diff options
author | Erona | 2018-10-29 22:32:14 +0800 |
---|---|---|
committer | Erona | 2018-10-29 23:11:32 +0800 |
commit | 79842b82e8c8383ed22fce1edfe1035d5a02fc18 (patch) | |
tree | 5068bce38d788822a398d3429e4c47ffe8b2cd64 /bin/manage_users | |
parent | 63626b1267e77ad792f426b4e0a8e4efac4b2c95 (diff) |
refactor(bin): add function getPass in bin/manage_users
Signed-off-by: Erona <erona@loli.bz>
Diffstat (limited to '')
-rwxr-xr-x | bin/manage_users | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/bin/manage_users b/bin/manage_users index f748e342..0d99f36b 100755 --- a/bin/manage_users +++ b/bin/manage_users @@ -22,6 +22,15 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email process.exit(1); } +function getPass(argv, action) { + // Find whether we use cmdline or prompt password + if(typeof argv["pass"] !== 'string') { + return readline.question(`Password for ${argv[action]}:`, {hideEchoBack: true}); + } + console.log("Using password from commandline..."); + return argv["pass"]; +} + // Using an async function to be able to use await inside async function createUser(argv) { const existing_user = await models.User.findOne({where: {email: argv["add"]}}); @@ -31,14 +40,8 @@ async function createUser(argv) { process.exit(1); } - // Find whether we use cmdline or prompt password - let pass; - if(argv["pass"] == undefined) { - pass = readline.question(`Password for ${argv["add"]}:`, {hideEchoBack: true}); - } else { - console.log("Using password from commandline..."); - pass = "" + argv["pass"]; - } + const pass = getPass(argv, "add"); + // Lets try to create, and check success const ref = await models.User.create({email: argv["add"], password: pass}); |