This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
80 lines (66 loc) · 2.11 KB
/
install.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
var mongoose = require('mongoose'),
User = require('./models/user'),
utils = require('./utils/function'),
config = require('./config'),
EMAIL,
PASSWORD,
stdin = process.stdin,
stdout = process.stdout,
env = process.argv.slice(2)[0] || 'development';
mongoose.connect(config.db[env].uri);
function ask(param) {
var question = param.question,
validate = param.validate,
errorMsg = param.errorMsg,
callback = param.callback;
stdin.resume();
stdout.write(question + ": ");
stdin.once('data', function (data) {
data = data.toString().trim();
if ( !validate(data) ){
stdout.write(errorMsg + "\n");
ask(param);
} else {
callback(data);
}
});
}
stdout.write('Welcome to Bookmarks! ' + "\n");
stdout.write('Before to continue, you need to create your account ' + "\n");
ask({
question: 'Enter your email',
errorMsg: 'Please, enter a valid email',
validate: function (email) {
return utils.isEmail(email);
},
callback: function (data) {
EMAIL = data;
//ask password
ask({
question: 'Enter your password',
validate: function () {
return true
},
callback: function (data) {
PASSWORD = data;
User.remove({},function (err) {
if (err) {
console.log('Error: ' + err);
}
//Create the admin user
var admin = new User({
email: EMAIL,
password: PASSWORD,
passwordConfirm: PASSWORD
});
admin.save(function (error, user) {
stdout.write('Your account has been created ' + "\n");
stdout.write('Email: ' + user.email + "\n");
stdout.write('Password: ' + PASSWORD);
process.exit(1);
});
});
}
})
}
});