Refactor code, split routes, change url in backend and update in frontend. Still have bugs, infinite loading after signup?
This commit is contained in:
11
backend/utils/database.js
Normal file
11
backend/utils/database.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mysql = require("mysql2");
|
||||
|
||||
//Create a pool of connection to allow multiple query happen at the same time
|
||||
const pool = mysql.createPool({
|
||||
host: "localhost",
|
||||
user: "root",
|
||||
database: "marketplace",
|
||||
password: "12345678",
|
||||
});
|
||||
|
||||
module.exports = pool.promise();
|
||||
33
backend/utils/helper.js
Normal file
33
backend/utils/helper.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const { generateEmailTransporter } = require("./mail");
|
||||
|
||||
// Helper function to send email
|
||||
async function sendVerificationEmail(email, verificationCode) {
|
||||
const transporter = generateEmailTransporter();
|
||||
|
||||
// Send the email with Zoho
|
||||
await transporter.sendMail({
|
||||
from: "campusplug@zohomailcloud.ca",
|
||||
to: email,
|
||||
subject: "Campus Plug: Signup Verification Code",
|
||||
text: `Your verification code is: ${verificationCode}. This code will expire in 15 minutes.`,
|
||||
html: `<p>Your verification code is: <strong>${verificationCode}</strong></p><p>This code will expire in 15 minutes.</p>`,
|
||||
});
|
||||
|
||||
console.log(`Verification code sent to ${email}`);
|
||||
}
|
||||
|
||||
// Clean up expired verification codes (run this periodically)
|
||||
function cleanupExpiredCodes() {
|
||||
db_con.query(
|
||||
"DELETE FROM AuthVerification WHERE Date < DATE_SUB(NOW(), INTERVAL 15 MINUTE) AND Authenticated = 0",
|
||||
(err, result) => {
|
||||
if (err) {
|
||||
console.error("Error cleaning up expired codes:", err);
|
||||
} else {
|
||||
console.log(`Cleaned up ${result} expired verification codes`);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { sendVerificationEmail, cleanupExpiredCodes };
|
||||
12
backend/utils/mail.js
Normal file
12
backend/utils/mail.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const nodemailer = require("nodemailer");
|
||||
|
||||
exports.generateEmailTransporter = () =>
|
||||
nodemailer.createTransport({
|
||||
host: "smtp.zohocloud.ca",
|
||||
secure: true,
|
||||
port: 465,
|
||||
auth: {
|
||||
user: "campusplug@zohomailcloud.ca", //Zoho email
|
||||
pass: "e0YRrNSeJZQd", //Zoho password
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user