File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email
1717 Options:
1818 --add Add user with the specified user-email
1919 --del Delete user with specified user-email
20+ --reset Reset user password with specified user-email
2021 --pass Use password from cmdline rather than prompting
2122` ) ;
2223 process . exit ( 1 ) ;
@@ -67,9 +68,28 @@ async function deleteUser(argv) {
6768 console . log ( `Deleted user ${ argv [ "del" ] } ...` ) ;
6869}
6970
70- var options = {
71+
72+ // Using an async function to be able to use await inside
73+ async function resetUser ( argv ) {
74+ const existing_user = await models . User . findOne ( { where : { email : argv [ "reset" ] } } ) ;
75+ // Cannot reset non-existing users
76+ if ( existing_user == undefined ) {
77+ console . log ( `User with e-mail ${ argv [ "reset" ] } does not exist, cannot reset` ) ;
78+ process . exit ( 1 ) ;
79+ }
80+
81+ const pass = getPass ( argv , "reset" ) ;
82+
83+ // set password and save
84+ existing_user . password = pass ;
85+ await existing_user . save ( ) ;
86+ console . log ( `User with email ${ argv [ "reset" ] } password has been reset` ) ;
87+ }
88+
89+ const options = {
7190 add : createUser ,
7291 del : deleteUser ,
92+ reset : resetUser ,
7393} ;
7494
7595// Perform commandline-parsing
You can’t perform that action at this time.
0 commit comments