diff options
author | Erona | 2018-10-29 22:33:26 +0800 |
---|---|---|
committer | Erona | 2018-10-29 23:11:32 +0800 |
commit | e90d4d824b3e75486e98c7498faedbc285876014 (patch) | |
tree | 05270efd96942e9ed0425f21fcd589d2596f7d69 /bin | |
parent | 79842b82e8c8383ed22fce1edfe1035d5a02fc18 (diff) |
feat(bin): add option --reset to reset user password
Signed-off-by: Erona <erona@loli.bz>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/manage_users | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/bin/manage_users b/bin/manage_users index 0d99f36b..b23a0c5a 100755 --- a/bin/manage_users +++ b/bin/manage_users @@ -17,6 +17,7 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email Options: --add Add user with the specified user-email --del Delete user with specified user-email + --reset Reset user password with specified user-email --pass Use password from cmdline rather than prompting `); process.exit(1); @@ -67,9 +68,28 @@ async function deleteUser(argv) { console.log(`Deleted user ${argv["del"]} ...`); } -var options = { + +// Using an async function to be able to use await inside +async function resetUser(argv) { + const existing_user = await models.User.findOne({where: {email: argv["reset"]}}); + // Cannot reset non-existing users + if(existing_user == undefined) { + console.log(`User with e-mail ${argv["reset"]} does not exist, cannot reset`); + process.exit(1); + } + + const pass = getPass(argv, "reset"); + + // set password and save + existing_user.password = pass; + await existing_user.save(); + console.log(`User with email ${argv["reset"]} password has been reset`); +} + +const options = { add: createUser, del: deleteUser, + reset: resetUser, }; // Perform commandline-parsing |