-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
169 lines (133 loc) · 3.8 KB
/
Copy pathdatabase.js
File metadata and controls
169 lines (133 loc) · 3.8 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const mysql = require('mysql2');
const bcrypt = require('bcrypt');
const dotenv = require('dotenv');
const nodemailer = require('nodemailer');
const { Voter,Eligibility } = require('./models');
dotenv.config();
const pool = mysql.createPool({
mysql.createConnection({host:"sonavotingapp-server.mysql.database.azure.com", user:"vgnqykuftr", password:"K4$viQkXVEHIQiZi", database:"online_voting_application", port:3306, ssl:{ca:fs.readFileSync("{ca-cert filename}")}});
}).promise()
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false,
auth: {
user: 'keerthikumar.21it@sonatech.ac.in',
pass: process.env.MAIL_PASS
}
});
// async function get_admin(username) {
// if (username) {
// const user = await pool.query("select admin_id,pass_word from admin where admin_id=?", [username]);
// return user[0];
// }
// else {
// console.log("Error in getting value from function parameter");
// }
// }
async function insert_voters(reg_no, pass, name, year, section, dept,email) {
bcrypt.hash(pass, 12, async function (err, hash) {
try{
const newVoter = await Voter.create({
reg_no: reg_no,
pass_word: hash,
name: name,
year: year,
section: section,
dept: dept,
email: email
});
console.log(newVoter);
if (newVoter) {
if (year == 1 || year == 2) {
await Eligibility.create({
id: null,
reg_no: reg_no,
roles: "REP",
status: 0
});
}
else if (year == 3) {
await Eligibility.bulkCreate([
{
id: null,
reg_no: reg_no,
roles: "REP",
status: 0
},
{
id: null,
reg_no: reg_no,
roles: "SC",
status: 0
}
]);
}
else if (year == 4) {
await Eligibility.bulkCreate([
{
id: null,
reg_no: reg_no,
roles: "REP",
status: 0
},
{
id: null,
reg_no: reg_no,
roles: "CHM",
status: 0
}
]);
}
console.log("inserted sucessfully")
}
else {
console.log("inserted failed")
}
}
catch(error){
console.log(error);
}
// try{
// console.log(email);
// const mailOptions = {
// from: `"Depatment of IT&ADS" `,
// to: email,
// subject: 'Your Voter Credentials',
// text: `Hello,${name}
// Here are your voter credentials:
// Username: ${reg_no}
// Password: ${pass}
// Please keep these credentials secure.
// Best regards,
// Your Service Name`,
// html: `<p>Hello,</p>
// <p>Here are your voter credentials:</p>
// <p>Username: <b>${reg_no}</b></p>
// <p>Password: <b>${pass}</b></p>
// <p>Please keep these credentials secure.</p>
// <p>Best regards,<br>Election committe</p>`
// };
// await transporter.sendMail(mailOptions);
// }
// catch(error){
// console.log(error);
// console.log("Email not sent");
// }
});
}
// async function insert_admin(user_name, pass) {
// bcrypt.hash(pass, 12, async function (err, hash) {
// const r = await pool.query('insert into admin values(?,?)', [user_name, hash]);
// if (r) {
// console.log("inserted sucessfully")
// }
// else {
// console.log("inserted failed")
// }
// });
// }
//insert_voters("61781921106056","123456","Keerthi",4,"B","IT","keerthikumar.21it@sonatech.ac.in");
module.exports = {
// get_admin,
}