1 import * as program from 'commander'
2 import { initDatabaseModels } from '../server/initializers'
3 import { UserModel } from '../server/models/account/user'
4 import { isUserPasswordValid } from '../server/helpers/custom-validators/users'
7 .option('-u, --user [user]', 'User')
10 if (program['user'] === undefined) {
11 console.error('All parameters are mandatory.')
15 initDatabaseModels(true)
17 return UserModel.loadByUsername(program['user'])
21 console.error('User unknown.')
25 const readline = require('readline')
26 const Writable = require('stream').Writable
27 const mutableStdout = new Writable({
28 write: function (chunk, encoding, callback) {
32 const rl = readline.createInterface({
34 output: mutableStdout,
38 console.log('New password?')
39 rl.on('line', function (password) {
40 if (!isUserPasswordValid(password)) {
41 console.error('New password is invalid.')
45 user.password = password
48 .then(() => console.log('User password updated.'))
49 .catch(err => console.error(err))
50 .finally(() => process.exit(0))