-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
29 lines (26 loc) · 874 Bytes
/
init.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
var UserHelper = require('./models/user.js');
var User = UserHelper.model;
// db setup
var dbConfig = require('./deploy/config').db;
var mongoose = require('mongoose');
mongoose.connect(dbConfig.url, { useNewUrlParser: true, useUnifiedTopology: true }, function(err, connection) {
if (err) {
console.log('Failed to connect to database: %o', err);
return;
}
console.log('Connected to database successfully');
var newUser = new User();
newUser.username = 'admin';
newUser.password = UserHelper.createPasswordHash('c3RyaW5nIGdlbmVyYXRvcg==');
newUser.role = 'proctor';
console.log('Creating user: %o', newUser);
// save the user
newUser.save(function(err) {
if (err) {
console.log('Error in saving user:', err);
process.exit(1);
}
console.log('Successfully registered ' + newUser.username);
process.exit(0);
});
});