diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-12 21:06:32 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-12 21:06:32 +0200 |
commit | 75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615 (patch) | |
tree | 016f64d0fc6cfee533516be40d76eaca1b1f837e /scripts/reset-password.ts | |
parent | 7593a21d13baad422efedfb658d7ceda4e0a8c6b (diff) | |
download | PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.tar.gz PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.tar.zst PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.zip |
Convert scripts to typescript
Diffstat (limited to 'scripts/reset-password.ts')
-rwxr-xr-x | scripts/reset-password.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts new file mode 100755 index 000000000..50e11c69c --- /dev/null +++ b/scripts/reset-password.ts | |||
@@ -0,0 +1,54 @@ | |||
1 | import * as program from 'commander' | ||
2 | |||
3 | import { database as db } from '../server/initializers/database' | ||
4 | |||
5 | program | ||
6 | .option('-u, --user [user]', 'User') | ||
7 | .parse(process.argv) | ||
8 | |||
9 | if (program.user === undefined) { | ||
10 | console.error('All parameters are mandatory.') | ||
11 | process.exit(-1) | ||
12 | } | ||
13 | |||
14 | db.init(true, function () { | ||
15 | db.User.loadByUsername(program.user, function (err, user) { | ||
16 | if (err) { | ||
17 | console.error(err) | ||
18 | return | ||
19 | } | ||
20 | |||
21 | if (!user) { | ||
22 | console.error('User unknown.') | ||
23 | return | ||
24 | } | ||
25 | |||
26 | const readline = require('readline') | ||
27 | const Writable = require('stream').Writable | ||
28 | const mutableStdout = new Writable({ | ||
29 | write: function (chunk, encoding, callback) { | ||
30 | callback() | ||
31 | } | ||
32 | }) | ||
33 | const rl = readline.createInterface({ | ||
34 | input: process.stdin, | ||
35 | output: mutableStdout, | ||
36 | terminal: true | ||
37 | }) | ||
38 | |||
39 | console.log('New password?') | ||
40 | rl.on('line', function (password) { | ||
41 | user.password = password | ||
42 | |||
43 | user.save().asCallback(function (err) { | ||
44 | if (err) { | ||
45 | console.error(err) | ||
46 | } else { | ||
47 | console.log('User password updated.') | ||
48 | } | ||
49 | |||
50 | process.exit(0) | ||
51 | }) | ||
52 | }) | ||
53 | }) | ||
54 | }) | ||