1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import { program } from 'commander'
5 import { initDatabaseModels } from '../server/initializers/database'
6 import { UserModel } from '../server/models/user/user'
7 import { isUserPasswordValid } from '../server/helpers/custom-validators/users'
10 .option('-u, --user [user]', 'User')
13 const options = program.opts()
15 if (options.user === undefined) {
16 console.error('All parameters are mandatory.')
20 initDatabaseModels(true)
22 return UserModel.loadByUsername(options.user)
26 console.error('Unknown user.')
30 const readline = require('readline')
31 const Writable = require('stream').Writable
32 const mutableStdout = new Writable({
33 write: function (_chunk, _encoding, callback) {
37 const rl = readline.createInterface({
39 output: mutableStdout,
43 console.log('New password?')
44 rl.on('line', function (password) {
45 if (!isUserPasswordValid(password)) {
46 console.error('New password is invalid.')
50 user.password = password
53 .then(() => console.log('User password updated.'))
54 .catch(err => console.error(err))
55 .finally(() => process.exit(0))