diff --git a/.env b/.env index f575297..4437be7 100644 --- a/.env +++ b/.env @@ -2,8 +2,8 @@ MONGODB_URI="mongodb://siinand:Qlenfrl1199424!@101.79.10.128:27017/local" # MONGODB_URI="mongodb://localhost:27017/local" PORT=5100 -# RECEIVING_EMAIL= -# EMAIL_PASSWORD= +RECEIVING_EMAIL=siinand@gmail.com +EMAIL_PASSWORD=Qlenfrl1199424! # SHIPPING_FEE= BASE_CURRENCY=KRW # STRIPE_SECRET_KEY= diff --git a/src/controllers/auth.js b/src/controllers/auth.js index 69c6ffc..b72fdc5 100644 --- a/src/controllers/auth.js +++ b/src/controllers/auth.js @@ -1,13 +1,100 @@ // controllers/userController.js -const User = require('../models/User'); -const Products = require('../models/Product'); -const jwt = require('jsonwebtoken'); -const bcrypt = require('bcrypt'); -const otpGenerator = require('otp-generator'); -const nodemailer = require('nodemailer'); -const fs = require('fs'); -const path = require('path'); -const { getUser } = require('../config/getUser'); +const User = require("../models/User"); +const Products = require("../models/Product"); +const jwt = require("jsonwebtoken"); +const bcrypt = require("bcrypt"); +const otpGenerator = require("otp-generator"); +const nodemailer = require("nodemailer"); +const fs = require("fs"); +const path = require("path"); +const { getUser } = require("../config/getUser"); +// const registerUser = async (req, res) => { +// try { +// // Create user in the database +// const request = req.body; // No need to use await here +// const UserCount = await User.countDocuments(); +// const existingUser = await User.findOne({ email: request.email }); + +// if (existingUser) { +// return res.status(400).json({ +// UserCount, +// success: false, +// message: 'User With This Email Already Exists', +// }); +// } + +// const otp = otpGenerator.generate(6, { +// upperCaseAlphabets: false, +// specialChars: false, +// lowerCaseAlphabets: false, +// digits: true, +// }); +// // Create user with the generated OTP +// const user = await User.create({ +// ...request, +// otp, +// role: Boolean(UserCount) ? request.role || 'user' : 'super admin', +// }); + +// // Generate JWT token +// const token = jwt.sign( +// { +// _id: user._id, +// // email: user.email, +// }, +// process.env.JWT_SECRET, +// { +// expiresIn: '7d', +// } +// ); +// // Path to the HTML file +// const htmlFilePath = path.join( +// process.cwd(), +// 'src/email-templates', +// 'otp.html' +// ); + +// // Read HTML file content +// let htmlContent = fs.readFileSync(htmlFilePath, 'utf8'); + +// // Replace the placeholder with the OTP and user email +// htmlContent = htmlContent.replace(/