diff options
Diffstat (limited to 'scripts/reset-password.js')
-rwxr-xr-x | scripts/reset-password.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/reset-password.js b/scripts/reset-password.js new file mode 100755 index 000000000..e5f59a267 --- /dev/null +++ b/scripts/reset-password.js | |||
@@ -0,0 +1,45 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | // TODO: document this script | ||
6 | |||
7 | const program = require('commander') | ||
8 | |||
9 | const constants = require('../server/initializers/constants') | ||
10 | const db = require('../server/initializers/database') | ||
11 | |||
12 | program | ||
13 | .option('-u, --user [user]', 'User') | ||
14 | .option('-p, --password [new password]', 'New password') | ||
15 | .parse(process.argv) | ||
16 | |||
17 | if (program.user === undefined || program.password === undefined) { | ||
18 | console.error('All parameters are mandatory.') | ||
19 | process.exit(-1) | ||
20 | } | ||
21 | |||
22 | db.init(true, function () { | ||
23 | db.User.loadByUsername(program.user, function (err, user) { | ||
24 | if (err) { | ||
25 | console.error(err) | ||
26 | return | ||
27 | } | ||
28 | |||
29 | if (!user) { | ||
30 | console.error('User unknown.') | ||
31 | return | ||
32 | } | ||
33 | |||
34 | user.password = program.password | ||
35 | user.save().asCallback(function (err) { | ||
36 | if (err) { | ||
37 | console.error(err) | ||
38 | return | ||
39 | } | ||
40 | |||
41 | console.log('User pasword updated.') | ||
42 | process.exit(0) | ||
43 | }) | ||
44 | }) | ||
45 | }) | ||