]>
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 | ||
0e1dc3e7 | 9 | if (program['user'] === undefined) { |
7df5e5e4 C |
10 | console.error('All parameters are mandatory.') |
11 | process.exit(-1) | |
12 | } | |
13 | ||
6fcd19ba C |
14 | db.init(true) |
15 | .then(() => { | |
0e1dc3e7 | 16 | return db.User.loadByUsername(program['user']) |
6fcd19ba C |
17 | }) |
18 | .then(user => { | |
7df5e5e4 C |
19 | if (!user) { |
20 | console.error('User unknown.') | |
fdbda9e3 | 21 | process.exit(-1) |
7df5e5e4 C |
22 | } |
23 | ||
c129e2a1 C |
24 | const readline = require('readline') |
25 | const Writable = require('stream').Writable | |
26 | const mutableStdout = new Writable({ | |
27 | write: function (chunk, encoding, callback) { | |
28 | callback() | |
7df5e5e4 | 29 | } |
c129e2a1 C |
30 | }) |
31 | const rl = readline.createInterface({ | |
32 | input: process.stdin, | |
33 | output: mutableStdout, | |
34 | terminal: true | |
35 | }) | |
36 | ||
37 | console.log('New password?') | |
38 | rl.on('line', function (password) { | |
39 | user.password = password | |
40 | ||
6fcd19ba C |
41 | user.save() |
42 | .then(() => console.log('User password updated.')) | |
43 | .catch(err => console.error(err)) | |
44 | .finally(() => process.exit(0)) | |
7df5e5e4 C |
45 | }) |
46 | }) |