diff options
Diffstat (limited to 'scripts/reset-password.ts')
-rwxr-xr-x | scripts/reset-password.ts | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts deleted file mode 100755 index b2e5639fb..000000000 --- a/scripts/reset-password.ts +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | import { program } from 'commander' | ||
2 | import { isUserPasswordValid } from '../server/helpers/custom-validators/users' | ||
3 | import { initDatabaseModels } from '../server/initializers/database' | ||
4 | import { UserModel } from '../server/models/user/user' | ||
5 | |||
6 | program | ||
7 | .option('-u, --user [user]', 'User') | ||
8 | .parse(process.argv) | ||
9 | |||
10 | const options = program.opts() | ||
11 | |||
12 | if (options.user === undefined) { | ||
13 | console.error('All parameters are mandatory.') | ||
14 | process.exit(-1) | ||
15 | } | ||
16 | |||
17 | initDatabaseModels(true) | ||
18 | .then(() => { | ||
19 | return UserModel.loadByUsername(options.user) | ||
20 | }) | ||
21 | .then(user => { | ||
22 | if (!user) { | ||
23 | console.error('Unknown user.') | ||
24 | process.exit(-1) | ||
25 | } | ||
26 | |||
27 | const readline = require('readline') | ||
28 | const Writable = require('stream').Writable | ||
29 | const mutableStdout = new Writable({ | ||
30 | write: function (_chunk, _encoding, callback) { | ||
31 | callback() | ||
32 | } | ||
33 | }) | ||
34 | const rl = readline.createInterface({ | ||
35 | input: process.stdin, | ||
36 | output: mutableStdout, | ||
37 | terminal: true | ||
38 | }) | ||
39 | |||
40 | console.log('New password?') | ||
41 | rl.on('line', function (password) { | ||
42 | if (!isUserPasswordValid(password)) { | ||
43 | console.error('New password is invalid.') | ||
44 | process.exit(-1) | ||
45 | } | ||
46 | |||
47 | user.password = password | ||
48 | |||
49 | user.save() | ||
50 | .then(() => console.log('User password updated.')) | ||
51 | .catch(err => console.error(err)) | ||
52 | .finally(() => process.exit(0)) | ||
53 | }) | ||
54 | }) | ||
55 | .catch(err => { | ||
56 | console.error(err) | ||
57 | process.exit(-1) | ||
58 | }) | ||