aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/reset-password.ts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/reset-password.ts')
-rwxr-xr-xscripts/reset-password.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts
new file mode 100755
index 000000000..50e11c69c
--- /dev/null
+++ b/scripts/reset-password.ts
@@ -0,0 +1,54 @@
1import * as program from 'commander'
2
3import { database as db } from '../server/initializers/database'
4
5program
6 .option('-u, --user [user]', 'User')
7 .parse(process.argv)
8
9if (program.user === undefined) {
10 console.error('All parameters are mandatory.')
11 process.exit(-1)
12}
13
14db.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})