forked from Strider-CD/strider-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-user.js
100 lines (82 loc) · 2.15 KB
/
add-user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
var Step = require('step');
var fs = require('fs');
var readline = require('readline');
var pw = require('pw');
module.exports = function(deps) {
var saveUser = require('./save-user')(deps);
var User = deps.models().User;
function addUser(email, password, admin, force) {
var level = admin ? 1 : 0;
if (!email || !password) {
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
Step(function getEmail() {
var next = this;
if (email) {
next();
} else {
rl.question('Enter email []: ', function (em) {
email = em;
next();
});
}
},
function getPwd() {
var next = this;
if (password) {
next();
} else {
rl.close();
process.stdout.write('Enter password []: ');
pw(function (pwd) {
password = pwd;
rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
next();
})
}
},
function getAdmin() {
var next = this;
if (level) {
next();
} else {
rl.question('Is admin? (y/n) [n]', function (a) {
level = a ? 1 : undefined;
next();
});
}
},
function confirm() {
var next = this;
process.stdout.write('\nEmail:\t\t' + email + '\n');
process.stdout.write('Password:\t' + password.replace(/.*/, '****') + '\n');
process.stdout.write('isAdmin:\t' + (level ? 'y' : 'n') + '\n');
if (force) {
next();
}
else {
rl.question('OK? (y/n) [y]', function (ok) {
if (ok === 'y' || ok === '') {
next();
} else {
console.log('Goodbye!');
process.exit();
}
});
}
},
function save() {
saveUser(email, password, level, rl, force);
});
} else {
saveUser(email, password, level, rl, force);
}
}
return addUser;
}