const express = require('express');
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.json());
let otpStore = {}; // Store OTPs temporarily for verification
// Simulate OTP generation and email sending
app.post('/send-otp/:serialNo', (req, res) => {
const serialNo = req.params.serialNo;
const otp = Math.floor(100000 + Math.random() * 900000); // 6 digit OTP
otpStore[serialNo] = otp;
// Use NodeMailer or any other library to send OTP to student's email
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'your_email@gmail.com',
pass: 'your_email_password'
}
});
const mailOptions = {
from: 'your_email@gmail.com',
to: 'student_email@example.com', // Replace with the actual email
subject: 'OTP for ID Card Verification',
text: `Your OTP is: ${otp}`
};
transporter.sendMail(mailOptions, (err, info) => {
if (err) {
return res.status(500).json({ success: false, message: 'Error sending OTP.' });
}
res.json({ success: true });
});
});
// Verify OTP
app.post('/verify-otp', (req, res) => {
const { otp, serialNo } = req.body;
if (otpStore[serialNo] === parseInt(otp)) {
res.json({ success: true });
} else {
res.json({ success: false });
}
});
// Handle student detail submission
app.post('/submit_student_details', (req, res) => {
const studentDetails = req.body;
console.log(studentDetails); // Save this to the database
res.json({ success: true });
});
// Track QR code scan requests
app.post('/track-scan', (req, res) => {
const { serialNo, contactNo } = req.body;
// Send email to the admin team
const mailOptions = {
from: 'your_email@gmail.com',
to: 'identification@jaipuriaschoolballia.com',
subject: 'QR Code Scan Request',
text: `A QR code with serial number ${serialNo} was scanned. Contact Number: ${contactNo}`
};
nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'your_email@gmail.com',
pass: 'your_email_password'
}
}).sendMail(mailOptions, (err, info) => {
if (err) {
return res.status(500).json({ success: false, message: 'Error sending request.' });
}
res.json({ success: true });
});
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});