0% found this document useful (0 votes)
3 views

dummyadminotpcode

The document outlines a Node.js application that implements an OTP (One-Time Password) system using Nodemailer for email notifications. It includes endpoints for sending an OTP to a user's email and verifying the OTP, with the OTP being valid for 10 minutes. If the OTP is verified successfully, the corresponding record is deleted from the database.

Uploaded by

abhilash
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

dummyadminotpcode

The document outlines a Node.js application that implements an OTP (One-Time Password) system using Nodemailer for email notifications. It includes endpoints for sending an OTP to a user's email and verifying the OTP, with the OTP being valid for 10 minutes. If the OTP is verified successfully, the corresponding record is deleted from the database.

Uploaded by

abhilash
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Admin Login start

// Nodemailer setup
// const transporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// user: '[email protected]',
// pass: 'wuve esae ixbx ccvk',
// },
// });

// // Send OTP endpoint


// app.post('/api/send-otp', async (req, res) => {
// const { email } = req.body;
// const otp = crypto.randomInt(100000, 999999).toString();
// const expiresAt = new Date(Date.now() + 10 * 60 * 1000); // OTP valid for 10
minutes

// await Otp.updateOne({ email }, { otp, expiresAt }, { upsert: true });

// const mailOptions = {
// from: '[email protected]',
// to: email,
// subject: 'Your OTP Code',
// text: `Your OTP code is ${otp}`,
// };

// try {
// await transporter.sendMail(mailOptions);
// res.status(200).send('OTP sent successfully');
// } catch (error) {
// res.status(500).send('Failed to send OTP');
// }
// });

// // Verify OTP endpoint


// app.post('/api/verify-otp', async (req, res) => {
// const { email, otp } = req.body;

// const record = await Otp.findOne({ email, otp, expiresAt: { $gt: new


Date() } });

// if (record) {
// await Otp.deleteOne({ email }); // Clean up the OTP record
// res.status(200).send('OTP verified successfully');
// } else {
// res.status(400).send('Invalid or expired OTP');
// }
// });
// //Admin Login end

You might also like