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'
7 .option('-u, --user [user]', 'User')
10 const options = program.opts()
12 if (options.user === undefined) {
13 console.error('All parameters are mandatory.')
17 initDatabaseModels(true)
19 return UserModel.loadByUsername(options.user)
23 console.error('Unknown user.')
27 const readline = require('readline')
28 const Writable = require('stream').Writable
29 const mutableStdout = new Writable({
30 write: function (_chunk, _encoding, callback) {
34 const rl = readline.createInterface({
36 output: mutableStdout,
40 console.log('New password?')
41 rl.on('line', function (password) {
42 if (!isUserPasswordValid(password)) {
43 console.error('New password is invalid.')
47 user.password = password
50 .then(() => console.log('User password updated.'))
51 .catch(err => console.error(err))
52 .finally(() => process.exit(0))