File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email
17
17
Options:
18
18
--add Add user with the specified user-email
19
19
--del Delete user with specified user-email
20
+ --reset Reset user password with specified user-email
20
21
--pass Use password from cmdline rather than prompting
21
22
` ) ;
22
23
process . exit ( 1 ) ;
@@ -67,9 +68,28 @@ async function deleteUser(argv) {
67
68
console . log ( `Deleted user ${ argv [ "del" ] } ...` ) ;
68
69
}
69
70
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 = {
71
90
add : createUser ,
72
91
del : deleteUser ,
92
+ reset : resetUser ,
73
93
} ;
74
94
75
95
// Perform commandline-parsing
You can’t perform that action at this time.
0 commit comments