-
Notifications
You must be signed in to change notification settings - Fork 4
/
addUser.js
32 lines (27 loc) · 853 Bytes
/
addUser.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
/**********************
A simple script to add a new user
**********************/
// Includes
var crypto = require('crypto');
function hashString(value) {
hash = crypto.createHash('sha1');
hash.update(value);
return hash.digest('hex');
}
// Database
var Database = require('./lib/Database');
var db = new Database();
db.connect('mongodb://localhost/mv');
if(process.argv.length == 4){
// 0 will be node, 1 will be the script
var au = db.model('adminUser');
var usr = new au({login: process.argv[2], password: hashString(process.argv[3]) });
usr.save(function(err){
console.log("User added to database");
process.exit(0); // Success
});
}else{
console.error("Script requires exactly 2 arguments");
console.error("Usage: node addUser.js <email> <password>");
process.exit(1); // Failure
}