]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
75d612ce | 4 | import * as program from 'commander' |
91fea9fc | 5 | import { initDatabaseModels } from '../server/initializers' |
3fd3ab2d | 6 | import { UserModel } from '../server/models/account/user' |
285e04f6 | 7 | import { isUserPasswordValid } from '../server/helpers/custom-validators/users' |
7df5e5e4 C |
8 | |
9 | program | |
10 | .option('-u, --user [user]', 'User') | |
7df5e5e4 C |
11 | .parse(process.argv) |
12 | ||
0e1dc3e7 | 13 | if (program['user'] === undefined) { |
7df5e5e4 C |
14 | console.error('All parameters are mandatory.') |
15 | process.exit(-1) | |
16 | } | |
17 | ||
91fea9fc | 18 | initDatabaseModels(true) |
6fcd19ba | 19 | .then(() => { |
3fd3ab2d | 20 | return UserModel.loadByUsername(program['user']) |
6fcd19ba C |
21 | }) |
22 | .then(user => { | |
7df5e5e4 C |
23 | if (!user) { |
24 | console.error('User unknown.') | |
fdbda9e3 | 25 | process.exit(-1) |
7df5e5e4 C |
26 | } |
27 | ||
c129e2a1 C |
28 | const readline = require('readline') |
29 | const Writable = require('stream').Writable | |
30 | const mutableStdout = new Writable({ | |
31 | write: function (chunk, encoding, callback) { | |
32 | callback() | |
7df5e5e4 | 33 | } |
c129e2a1 C |
34 | }) |
35 | const rl = readline.createInterface({ | |
36 | input: process.stdin, | |
37 | output: mutableStdout, | |
38 | terminal: true | |
39 | }) | |
40 | ||
41 | console.log('New password?') | |
42 | rl.on('line', function (password) { | |
285e04f6 C |
43 | if (!isUserPasswordValid(password)) { |
44 | console.error('New password is invalid.') | |
45 | process.exit(-1) | |
46 | } | |
47 | ||
c129e2a1 C |
48 | user.password = password |
49 | ||
6fcd19ba C |
50 | user.save() |
51 | .then(() => console.log('User password updated.')) | |
52 | .catch(err => console.error(err)) | |
53 | .finally(() => process.exit(0)) | |
7df5e5e4 C |
54 | }) |
55 | }) |