-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.js
88 lines (70 loc) · 2.03 KB
/
import.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
var torii = require(__dirname + '/torii.conf.js').torii;
var mongoose = require('mongoose');
mongoose.connect('mongodb://' + torii.conf.db.host + '/' + torii.conf.db.user);
var account = require(__dirname + '/model/account');
var rbac = require('mongoose-rbac');
var role = rbac.Role;
var permission = rbac.Permission;
var userRole = 'user'
var csv = require("fast-csv");
var nodemailer = require('nodemailer');
var transport = null;
if (torii.conf.mail.service == 'smtp') {
transport = require('nodemailer-smtp-transport');
} else {
transport = require('nodemailer-sendmail-transport');
}
if (transport == null) {
throw Error('Mail transport not setup, please check your configuration file');
}
/*var emailSetup = {};
if(torii.conf.mail.host){
emailSetup = {
host: torii.conf.mail.host,
port: torii.conf.mail.port,
secureConnection: torii.conf.mail.secureConnection,
auth: {
user: torii.conf.mail.user,
pass: torii.conf.mail.pass
}
};
}
var mail = nodemailer.createTransport(transport(emailSetup));*/
csv
.fromPath("user.csv", {
headers: false,
delimiter: ';'
})
.on("data", function(data) {
console.log(data);
account.register(new account({
username: data[0]
}), data[3], function(err, account) {
if (err) {
console.log(err)
return
}
account.name = data[1]
account.surname = data[2]
account.addRole(userRole, function(err) {
console.log(err)
})
account.save()
/*var mailOptions = {
from: torii.conf.mail.from,
to: data[0],
subject: torii.conf.core.title + ' - Password Confirmation',
text: 'Dear ' + data[1] + ' ' + data[2] + '\n here your password: ' + data[3] + '\n\nPlease store it!'
};
mail.sendMail(mailOptions, function(err, info) {
if (err) {
console.log(err);
return;
}
console.log(info);
});*/
});
})
.on("end", function() {
console.log("all users imported");
});