]>
Commit | Line | Data |
---|---|---|
75d612ce | 1 | import * as program from 'commander' |
7df5e5e4 | 2 | |
75d612ce | 3 | import { database as db } from '../server/initializers/database' |
7df5e5e4 C |
4 | |
5 | program | |
6 | .option('-u, --user [user]', 'User') | |
7df5e5e4 C |
7 | .parse(process.argv) |
8 | ||
c129e2a1 | 9 | if (program.user === undefined) { |
7df5e5e4 C |
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 | ||
c129e2a1 C |
26 | const readline = require('readline') |
27 | const Writable = require('stream').Writable | |
28 | const mutableStdout = new Writable({ | |
29 | write: function (chunk, encoding, callback) { | |
30 | callback() | |
7df5e5e4 | 31 | } |
c129e2a1 C |
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 | } | |
7df5e5e4 | 49 | |
c129e2a1 C |
50 | process.exit(0) |
51 | }) | |
7df5e5e4 C |
52 | }) |
53 | }) | |
54 | }) |