-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlFunction.js
More file actions
77 lines (76 loc) · 2.66 KB
/
Copy pathSqlFunction.js
File metadata and controls
77 lines (76 loc) · 2.66 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
var mysql=require('mysql');
var connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'@Aashish1',
database:'prototypeproject'
});
var nodemailer=require('nodemailer');
var transporter=nodemailer.createTransport({
service:'Gmail',
host:'smtp.gmail.com',
port:5000,
secure:'true',
auth:{
user:'hellocollege143@gmail.com',
pass:'qgpx acjz lztl dgyj',
},
});
module.exports = {
Insertion: Insertion,
sendemail: sendemail
};
connection.connect(function(error){
if(error) throw error;
});
function sendemail(username, name, email) {
return new Promise((resolve, reject) => {
const myArray = new Uint32Array(1);
function generateOTP() {
const myArray = new Uint32Array(2);
crypto.getRandomValues(myArray);
let otp = (myArray[0] % 1000000).toString().padStart(6, '0');
return otp;
}
const x = generateOTP();
const mailOptions = {
from: "hellocollege143@gmail.com",
to: `${email}`,
subject: `User Verification`,
text: `This message was supposed for the user having username as ${username} and name as ${name}, If this was not you then please ignore this message. The OTP is ${x}`,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
reject(error);
} else {
// console.log("Email sent!");
resolve(x);
}
});
});
}
function Insertion(username,fullname,email,password){
var query;
query=`INSERT INTO userinfo(userName,name,eMail,password) VALUES ('${username}','${fullname}','${email}','${password}')`;
// console.log(query);
connection.query(query,function(error,result){
if(error) throw error;
console.log("data inserted successfully!");
});
query = `CREATE TABLE ?? (
id INT AUTO_INCREMENT,
issue VARCHAR(10000) NOT NULL,
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
date DATETIME DEFAULT CURRENT_TIMESTAMP,
upvote INT DEFAULT 0,
downvote INT DEFAULT 0,
PRIMARY KEY (id)
)`;
connection.query(query, [username], function(error, result) {
if (error) {
console.error("Error creating table:", error);
} else {
console.log("Table created successfully.");
}
});
}