1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import * as program from 'commander'
5 import { initDatabaseModels } from '../server/initializers/database'
6 import { UserModel } from '../server/models/account/user'
7 import { isUserPasswordValid } from '../server/helpers/custom-validators/users'
10 .option('-u, --user [user]', 'User')
13 if (program['user'] === undefined) {
14 console.error('All parameters are mandatory.')
18 initDatabaseModels(true)
20 return UserModel.loadByUsername(program['user'])
24 console.error('Unknown user.')
28 const readline = require('readline')
29 const Writable = require('stream').Writable
30 const mutableStdout = new Writable({
31 write: function (chunk, encoding, callback) {
35 const rl = readline.createInterface({
37 output: mutableStdout,
41 console.log('New password?')
42 rl.on('line', function (password) {
43 if (!isUserPasswordValid(password)) {
44 console.error('New password is invalid.')
48 user.password = password
51 .then(() => console.log('User password updated.'))
52 .catch(err => console.error(err))
53 .finally(() => process.exit(0))