diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-15 10:05:53 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-15 10:05:53 +0100 |
commit | 7df5e5e4b1602ce412b310dd88c83bac937d0a35 (patch) | |
tree | a8c4f50cd2001fbf69b18476a649f27574573972 /scripts/reset-password.js | |
parent | cdcbc81077a6ca3ef2f23a3e93260a6ffe1a4332 (diff) | |
download | PeerTube-7df5e5e4b1602ce412b310dd88c83bac937d0a35.tar.gz PeerTube-7df5e5e4b1602ce412b310dd88c83bac937d0a35.tar.zst PeerTube-7df5e5e4b1602ce412b310dd88c83bac937d0a35.zip |
Server: add script that reset the password of a user
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 | }) | ||