]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/reset-password.ts
50e11c69c0195fbe4b7d446e7c0864d0ae5e30d2
[github/Chocobozzz/PeerTube.git] / scripts / reset-password.ts
1 import * as program from 'commander'
2
3 import { database as db } from '../server/initializers/database'
4
5 program
6 .option('-u, --user [user]', 'User')
7 .parse(process.argv)
8
9 if (program.user === undefined) {
10 console.error('All parameters are mandatory.')
11 process.exit(-1)
12 }
13
14 db.init(true, function () {
15 db.User.loadByUsername(program.user, function (err, user) {
16 if (err) {
17 console.error(err)
18 return
19 }
20
21 if (!user) {
22 console.error('User unknown.')
23 return
24 }
25
26 const readline = require('readline')
27 const Writable = require('stream').Writable
28 const mutableStdout = new Writable({
29 write: function (chunk, encoding, callback) {
30 callback()
31 }
32 })
33 const rl = readline.createInterface({
34 input: process.stdin,
35 output: mutableStdout,
36 terminal: true
37 })
38
39 console.log('New password?')
40 rl.on('line', function (password) {
41 user.password = password
42
43 user.save().asCallback(function (err) {
44 if (err) {
45 console.error(err)
46 } else {
47 console.log('User password updated.')
48 }
49
50 process.exit(0)
51 })
52 })
53 })
54 })