From f4ac5978a8f1dcb0c9f1ef32e9706006b37978fe Mon Sep 17 00:00:00 2001 From: hardcodder Date: Mon, 10 May 2021 14:30:02 +0530 Subject: [PATCH 1/5] for bugs --- controllers/payment.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/payment.js b/controllers/payment.js index 394a24f..4ae8264 100644 --- a/controllers/payment.js +++ b/controllers/payment.js @@ -108,6 +108,9 @@ module.exports.postRazorpay = async (req , res , next) => { const courseId = req.body.courseId ; const couponCode = req.body.couponCode ; const userId = req.user._id ; + + console.log(courseId , couponCode , userId) ; + let user = await User.findById(userId) ; let student =await Student.findById(user.student) ; let course =await CourseType.findById(courseId) ; From 03a373620aaba1b714c460933da0a66a11eb242a Mon Sep 17 00:00:00 2001 From: hardcodder Date: Mon, 10 May 2021 14:32:44 +0530 Subject: [PATCH 2/5] for bugs --- controllers/payment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/payment.js b/controllers/payment.js index 4ae8264..555dbf5 100644 --- a/controllers/payment.js +++ b/controllers/payment.js @@ -109,7 +109,7 @@ module.exports.postRazorpay = async (req , res , next) => { const couponCode = req.body.couponCode ; const userId = req.user._id ; - console.log(courseId , couponCode , userId) ; + console.log("Course ID =" ,courseId ," Coupon code =" , couponCode ," user ID =" , userId) ; let user = await User.findById(userId) ; let student =await Student.findById(user.student) ; From d25cc5b42fa5c837c09e52a7869736306c7a378b Mon Sep 17 00:00:00 2001 From: yashraj verma Date: Wed, 19 May 2021 12:38:12 +0530 Subject: [PATCH 3/5] Delete .history directory --- .history/app_20210519122521.js | 112 ------ .history/app_20210519122841.js | 107 ----- .history/controllers/auth_20210519122521.js | 419 -------------------- .history/controllers/auth_20210519122752.js | 404 ------------------- .history/controllers/auth_20210519123339.js | 405 ------------------- 5 files changed, 1447 deletions(-) delete mode 100644 .history/app_20210519122521.js delete mode 100644 .history/app_20210519122841.js delete mode 100644 .history/controllers/auth_20210519122521.js delete mode 100644 .history/controllers/auth_20210519122752.js delete mode 100644 .history/controllers/auth_20210519123339.js diff --git a/.history/app_20210519122521.js b/.history/app_20210519122521.js deleted file mode 100644 index 2f07095..0000000 --- a/.history/app_20210519122521.js +++ /dev/null @@ -1,112 +0,0 @@ -const express = require("express"); -const mongoose = require("mongoose"); -const bodyparser = require("body-parser"); -const authRoute = require("./routes/auth"); -const profileRoute = require("./routes/profile"); -const paymentRoute = require("./routes/payment"); -const courseRoute = require("./routes/course"); -const couponRoute = require("./routes/Coupon"); -const queryRoute = require("./routes/query"); -const adminRoute = require("./routes/admin"); -const blogRouter = require("./routes/blog"); -const port = process.env.PORT || 5000; -const cors = require("cors"); -const app = express(); - -//const passport = require('passport'); -//const cookieSession = require('cookie-session') ; -//require('./passport-setup') ; - -<<<<<<< HEAD -======= -const app = express(); - ->>>>>>> ef4c9b6a526e0ef10b94f271654809ce636d8ab0 -const MONGO_URI = `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.dqxva.mongodb.net/${process.env.MONGO_DEFAULT_DATABASE}?retryWrites=true&w=majority`; - -app.use(cors()); -app.use(bodyparser.json()); - -// app.use(cookieSession({ -// name: 'test-session', -// keys: ['key1', 'key2'] -// })) - -// const isLoggedIn = (req , res , next) => { -// if(req.user) -// { -// next() -// } -// else -// { -// res.json({ -// error : "No user" -// }) -// } -// } - -// app.use(passport.initialize()); -// app.use(passport.session()); - -// app.get('/failed' , (req , res) => { -// res.json({ -// error : "You have failed to login" -// }) -// }) - -// app.get('/' , (req , res) => { -// console.log('you are not logged in'); - -// }) - -// app.get('/good' ,isLoggedIn , (req , res) => { -// res.json({ -// message:"success" , -// user : req.user -// }) -// }) - -// app.get('/auth/google', -// passport.authenticate('google', { scope: ['profile' , 'email'] })); - -// app.get('/auth/google/callback', -// passport.authenticate('google', { failureRedirect: '/failed' }), -// function(req, res) { -// res.redirect('/good'); -// }); - -// app.get('/logout', (req , res) => { -// req.session = null ; -// req.logout() ; -// res.redirect('/') ; -// }) -mongoose - .connect(MONGO_URI, { - useNewUrlParser: true, - useUnifiedTopology: true, - useFindAndModify: false, - }) - .then((result) => { - console.log("connected"); - app.listen(port, () => { - console.log("server is running on port", port); - }); - }) - .catch((err) => { - console.log(err); - }); -app.use(authRoute); - -app.use(profileRoute); - -app.use(paymentRoute); - -app.use(courseRoute); - -app.use(adminRoute); - -app.use(couponRoute); - -app.use(blogRouter); - -app.use(queryRoute); diff --git a/.history/app_20210519122841.js b/.history/app_20210519122841.js deleted file mode 100644 index b02365d..0000000 --- a/.history/app_20210519122841.js +++ /dev/null @@ -1,107 +0,0 @@ -const express = require("express"); -const mongoose = require("mongoose"); -const bodyparser = require("body-parser"); -const authRoute = require("./routes/auth"); -const profileRoute = require("./routes/profile"); -const paymentRoute = require("./routes/payment"); -const courseRoute = require("./routes/course"); -const couponRoute = require("./routes/Coupon"); -const queryRoute = require("./routes/query"); -const adminRoute = require("./routes/admin"); -const blogRouter = require("./routes/blog"); -const port = process.env.PORT || 5000; -const cors = require("cors"); -const app = express(); - -//const passport = require('passport'); -//const cookieSession = require('cookie-session') ; -//require('./passport-setup') ; - -const MONGO_URI = `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.dqxva.mongodb.net/${process.env.MONGO_DEFAULT_DATABASE}?retryWrites=true&w=majority`; - -app.use(cors()); -app.use(bodyparser.json()); - -// app.use(cookieSession({ -// name: 'test-session', -// keys: ['key1', 'key2'] -// })) - -// const isLoggedIn = (req , res , next) => { -// if(req.user) -// { -// next() -// } -// else -// { -// res.json({ -// error : "No user" -// }) -// } -// } - -// app.use(passport.initialize()); -// app.use(passport.session()); - -// app.get('/failed' , (req , res) => { -// res.json({ -// error : "You have failed to login" -// }) -// }) - -// app.get('/' , (req , res) => { -// console.log('you are not logged in'); - -// }) - -// app.get('/good' ,isLoggedIn , (req , res) => { -// res.json({ -// message:"success" , -// user : req.user -// }) -// }) - -// app.get('/auth/google', -// passport.authenticate('google', { scope: ['profile' , 'email'] })); - -// app.get('/auth/google/callback', -// passport.authenticate('google', { failureRedirect: '/failed' }), -// function(req, res) { -// res.redirect('/good'); -// }); - -// app.get('/logout', (req , res) => { -// req.session = null ; -// req.logout() ; -// res.redirect('/') ; -// }) -mongoose - .connect(MONGO_URI, { - useNewUrlParser: true, - useUnifiedTopology: true, - useFindAndModify: false, - }) - .then((result) => { - console.log("connected"); - app.listen(port, () => { - console.log("server is running on port", port); - }); - }) - .catch((err) => { - console.log(err); - }); -app.use(authRoute); - -app.use(profileRoute); - -app.use(paymentRoute); - -app.use(courseRoute); - -app.use(adminRoute); - -app.use(couponRoute); - -app.use(blogRouter); - -app.use(queryRoute); diff --git a/.history/controllers/auth_20210519122521.js b/.history/controllers/auth_20210519122521.js deleted file mode 100644 index f9fd292..0000000 --- a/.history/controllers/auth_20210519122521.js +++ /dev/null @@ -1,419 +0,0 @@ -const bcrypt = require("bcryptjs"); -const User = require("../models/User"); -const Student = require("../models/Student"); -const jwt = require("jsonwebtoken"); -const JWT_secret = "Cantileverlabs"; -const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS", null, [ - "ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX", -]); -const nodemailer = require("nodemailer"); -const smtpTransport = require("nodemailer-smtp-transport"); - -// -------------------------------------------- mail transporter ----------------------------------------- - -var transport = nodemailer.createTransport( - smtpTransport({ - host: `email-smtp.us-east-1.amazonaws.com`, //`${process.env.HOST}` - port: 465, - auth: { - user: `AKIA2G7743RRTZMVXE3X`, //`${process.env.EMAIL}` - pass: `BJSjV3jArJfsnk1LhFc/hUmisEyEtbLNGgrRbv0noh8c`, //`${process.env.PASS}` - }, - }) -); - -// -------------------------------------------- mail transporter ----------------------------------------- - -module.exports.Protected = async (req, res, next) => { - res.send("Hello User"); -}; -module.exports.postSignup = async (req, res, next) => { - try { - //we need firstName , lastName , email , password as input - let firstName = req.body.firstName || " "; - let lastName = req.body.lastName || " "; - const { sending_company_email, email, password, subject } = req.body; - let user = await User.findOne({ email: email }); - if (user) { - res.json({ - message: "User already exist", - type: "error", - }); - } else { - const email_otp = Math.floor(100000 + Math.random() * 900000); - console.log("otp", email_otp); - const hashedPass = await bcrypt.hash(password, 12); - user = new User({ - firstName: firstName, - lastName: lastName, - email: email, - password: hashedPass, - isAdmin: false, - // email_otp, - }); - user = await user.save(); - await Student.deleteOne({ user: user._id }); - let student = new Student({ - user: user._id, - }); - student = await student.save(); - user.student = student._id; - await user.save(); - // const message = { - // from: `${sending_company_email}`, // Sender address - // to: `${email}`, // List of recipients - // subject: `${subject}`, // Subject line - // html: '', // design html for email message. - // }; - // transport.sendMail(message, function (err, info) { - // if (err) { - // console.log(err); - // } else { - // console.log(info); - // } - // }); - res.json({ - message: "You Are Registered, Please Login", - type: "success", - }); - } - } catch (err) { - console.log(err); - } -}; - -module.exports.verfiyemail = async (req, res, next) => { - const { email, otp } = req.body; - try { - let user = await User.findOne({ email: email }); - if (user) { - const isMatched = await (user.email_otp == otp ? true : false); - if (isMatched) { - if (!user.isVerified) { - user.isVerified = true; - await user.save(); - res.json({ - message: "User Verified, Please Login", - }); - } else { - res.json({ - message: "User Already Verified, Please Login", - }); - } - } else { - res.json({ - message: "OTP Doesn't Matched!", - type: "error", - }); - } - } else { - res.json({ - message: "No user with this email exists", - type: "error", - }); - } - } catch { - (err) => { - console.log(err); - }; - } -}; - -module.exports.postSignin = async (req, res, next) => { - try { - //we need email and password as input - let email = req.body.email; - let password = req.body.password; - let user = await User.findOne({ email: email }); - if (user) { - const isMatched = await bcrypt.compare(password, user.password); - if (isMatched) { - const token = jwt.sign({ _id: user._id }, JWT_secret); - res.json({ - token: token, - }); - } else { - res.json({ - message: "email and password doesn't match", - type: "error", - }); - } - } else { - res.json({ - message: "No user with this email exists", - type: "error", - }); - } - } catch (err) { - console.log(err); - } -}; - -// Phone verification Starts. -// ----------------------------------------------------------------------------------------------- - -module.exports.sendOTP = (req, res, next) => { - //uNNYosMopvvCW9RTR1tRWJmYC test - //llVKD53ve6QRpbCKOHzWBADaS live - const { phoneNumber } = req.body; - try { - if (!phoneNumber) { - res.status(422).json({ message: "Please Add All Required Fields" }); - return; - } else { - messagebird.verify.create( - phoneNumber, - { - template: "Your verification code is %token", - }, - function (err, response) { - if (err) { - console.log(err); - res.status(422).json({ message: err.errors[0].description }); - } else { - console.log(response); - res.json({ id: response.id }); - } - } - ); - } - } catch (err) { - console.log(err); - } -}; - -module.exports.getOTP = (req, res, next) => { - try { - const { id, otp } = req.body; - messagebird.verify.verify(id, otp, function (err, response) { - if (err) { - console.log({ error: err.errors[0].description, id: id }); - res.json({ error: err.errors[0].description, id: id }); - } else { - console.log(response); - res.json({ message: "Code Verified" }); - } - }); - } catch (err) { - console.log(err); - } -}; -// Phone verification End. -// ----------------------------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------------------------- -<<<<<<< HEAD -// Forgot password Starts - -module.exports.forgotpassword = async (req, res, next) => { - const { email, link, sending_company_email, subject } = req.body; -======= -// Email verification Starts - -var transport = nodemailer.createTransport({ - service: "gmail", - auth: { - user: "5578544cc56856", //replace it with the companies mail - pass: "a510d3d969d3b3", //replace it with the companies pass - }, -}); -module.exports.forgotpassword = async (req, res, next) => { - const { email, link, _html, sending_company_email, subject } = req.body; ->>>>>>> ef4c9b6a526e0ef10b94f271654809ce636d8ab0 - //link = https://cantileverlabs.herokuapp.com/resetpassword/:id/:token - try { - await User.findOne({ email }).then((user) => { - if (!user) { - res.status(404).json({ error: "User not found with this Email" }); - return; - } else { - const payload = { - email: user.email, - _id: user._id, - }; - const secret = JWT_secret + user.password; - const token = jwt.sign(payload, secret, { expiresIn: "10m" }); - User.findByIdAndUpdate(user._id, { - $set: { passwordResetToken: token }, - }) - .then((data) => { - const reset_link = `${link}/${user._id}/${token}`; - const message = { - from: `${sending_company_email}`, // Sender address - to: `${user.email}`, // List of recipients - subject: `${subject}`, // Subject line - html: ` - - - - - - Reset Password Email Template - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
 
- -
 
- - - - - - - - - - -
 
- - logo -

You have - requested to reset your password

- -

- We cannot simply send you your old password. A unique link to reset your - password has been generated for you. To reset your password, click the - following link and follow the instructions. -

- Reset - Password - -

- Facing any issue? Write us at -

info@cantileverlabs.com

-logo -

- Privacy Policy -Terms Of Use -Contact Us -

-

-
 
-
 
-
- - copyright 2018 Cantilever Labs -
-
 
-
- - - - - `, // design html for email message. - }; - transport.sendMail(message, function (err, info) { - if (err) { - console.log(err); - } else { - console.log(info); - } - }); - res.status(200).json({ - message: "Link is Active for 10 mins", - reset_link, - }); - }) - .catch((err) => { - console.log(err); - }); - } - }); - } catch { - (error) => { - console.log("Error from forgot pass", error); - }; - } -}; -module.exports.resetpassword = async (req, res, next) => { - const { _id, token } = req.params; - const { password } = req.body; - try { - let user = await User.findById({ _id }); - if (!user) { - res.json({ error: "User not Found or WrongId" }); - return; - } else { - const secret = JWT_secret + user.password; - const user_token = user.passwordResetToken; - const payload = jwt.verify(token, secret); - const hashedPass = await bcrypt.hash(password, 12); - if (token == user_token) { - user.password = hashedPass; - await user - .save() - .then((ok) => { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "*"); - res.json({ message: "Password Updated!" }); - }) - .catch((err) => { - console.log("Error in save", err); - }); - } else { - res.status(422).json({ error: "Either Token not found or Expired!" }); - return; - } - } - } catch { - (err) => { - console.log("error from try catch resetpass", err); - }; - } -}; - -<<<<<<< HEAD -// Forgot password Ends -======= -// Email verification Ends ->>>>>>> ef4c9b6a526e0ef10b94f271654809ce636d8ab0 -// ----------------------------------------------------------------------------------------------- - -module.exports.checkProtected = (req, res, next) => { - console.log(req.user); - res.json({ - message: "Protected", - user: req.user, - }); -}; diff --git a/.history/controllers/auth_20210519122752.js b/.history/controllers/auth_20210519122752.js deleted file mode 100644 index e8e42c9..0000000 --- a/.history/controllers/auth_20210519122752.js +++ /dev/null @@ -1,404 +0,0 @@ -const bcrypt = require("bcryptjs"); -const User = require("../models/User"); -const Student = require("../models/Student"); -const jwt = require("jsonwebtoken"); -const JWT_secret = "Cantileverlabs"; -const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS", null, [ - "ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX", -]); -const nodemailer = require("nodemailer"); -const smtpTransport = require("nodemailer-smtp-transport"); - -// -------------------------------------------- mail transporter ----------------------------------------- - -var transport = nodemailer.createTransport( - smtpTransport({ - host: `email-smtp.us-east-1.amazonaws.com`, //`${process.env.HOST}` - port: 465, - auth: { - user: `AKIA2G7743RRTZMVXE3X`, //`${process.env.EMAIL}` - pass: `BJSjV3jArJfsnk1LhFc/hUmisEyEtbLNGgrRbv0noh8c`, //`${process.env.PASS}` - }, - }) -); - -// -------------------------------------------- mail transporter ----------------------------------------- - -module.exports.Protected = async (req, res, next) => { - res.send("Hello User"); -}; -module.exports.postSignup = async (req, res, next) => { - try { - //we need firstName , lastName , email , password as input - let firstName = req.body.firstName || " "; - let lastName = req.body.lastName || " "; - const { sending_company_email, email, password, subject } = req.body; - let user = await User.findOne({ email: email }); - if (user) { - res.json({ - message: "User already exist", - type: "error", - }); - } else { - const email_otp = Math.floor(100000 + Math.random() * 900000); - console.log("otp", email_otp); - const hashedPass = await bcrypt.hash(password, 12); - user = new User({ - firstName: firstName, - lastName: lastName, - email: email, - password: hashedPass, - isAdmin: false, - // email_otp, - }); - user = await user.save(); - await Student.deleteOne({ user: user._id }); - let student = new Student({ - user: user._id, - }); - student = await student.save(); - user.student = student._id; - await user.save(); - // const message = { - // from: `${sending_company_email}`, // Sender address - // to: `${email}`, // List of recipients - // subject: `${subject}`, // Subject line - // html: '', // design html for email message. - // }; - // transport.sendMail(message, function (err, info) { - // if (err) { - // console.log(err); - // } else { - // console.log(info); - // } - // }); - res.json({ - message: "You Are Registered, Please Login", - type: "success", - }); - } - } catch (err) { - console.log(err); - } -}; - -module.exports.verfiyemail = async (req, res, next) => { - const { email, otp } = req.body; - try { - let user = await User.findOne({ email: email }); - if (user) { - const isMatched = await (user.email_otp == otp ? true : false); - if (isMatched) { - if (!user.isVerified) { - user.isVerified = true; - await user.save(); - res.json({ - message: "User Verified, Please Login", - }); - } else { - res.json({ - message: "User Already Verified, Please Login", - }); - } - } else { - res.json({ - message: "OTP Doesn't Matched!", - type: "error", - }); - } - } else { - res.json({ - message: "No user with this email exists", - type: "error", - }); - } - } catch { - (err) => { - console.log(err); - }; - } -}; - -module.exports.postSignin = async (req, res, next) => { - try { - //we need email and password as input - let email = req.body.email; - let password = req.body.password; - let user = await User.findOne({ email: email }); - if (user) { - const isMatched = await bcrypt.compare(password, user.password); - if (isMatched) { - const token = jwt.sign({ _id: user._id }, JWT_secret); - res.json({ - token: token, - }); - } else { - res.json({ - message: "email and password doesn't match", - type: "error", - }); - } - } else { - res.json({ - message: "No user with this email exists", - type: "error", - }); - } - } catch (err) { - console.log(err); - } -}; - -// Phone verification Starts. -// ----------------------------------------------------------------------------------------------- - -module.exports.sendOTP = (req, res, next) => { - //uNNYosMopvvCW9RTR1tRWJmYC test - //llVKD53ve6QRpbCKOHzWBADaS live - const { phoneNumber } = req.body; - try { - if (!phoneNumber) { - res.status(422).json({ message: "Please Add All Required Fields" }); - return; - } else { - messagebird.verify.create( - phoneNumber, - { - template: "Your verification code is %token", - }, - function (err, response) { - if (err) { - console.log(err); - res.status(422).json({ message: err.errors[0].description }); - } else { - console.log(response); - res.json({ id: response.id }); - } - } - ); - } - } catch (err) { - console.log(err); - } -}; - -module.exports.getOTP = (req, res, next) => { - try { - const { id, otp } = req.body; - messagebird.verify.verify(id, otp, function (err, response) { - if (err) { - console.log({ error: err.errors[0].description, id: id }); - res.json({ error: err.errors[0].description, id: id }); - } else { - console.log(response); - res.json({ message: "Code Verified" }); - } - }); - } catch (err) { - console.log(err); - } -}; -// Phone verification End. -// ----------------------------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------------------------- -// Forgot password Starts - -module.exports.forgotpassword = async (req, res, next) => { - const { email, link, sending_company_email, subject } = req.body; - //link = https://cantileverlabs.herokuapp.com/resetpassword/:id/:token - try { - await User.findOne({ email }).then((user) => { - if (!user) { - res.status(404).json({ error: "User not found with this Email" }); - return; - } else { - const payload = { - email: user.email, - _id: user._id, - }; - const secret = JWT_secret + user.password; - const token = jwt.sign(payload, secret, { expiresIn: "10m" }); - User.findByIdAndUpdate(user._id, { - $set: { passwordResetToken: token }, - }) - .then((data) => { - const reset_link = `${link}/${user._id}/${token}`; - const message = { - from: `${sending_company_email}`, // Sender address - to: `${user.email}`, // List of recipients - subject: `${subject}`, // Subject line - html: ` - - - - - - Reset Password Email Template - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
 
- -
 
- - - - - - - - - - -
 
- - logo -

You have - requested to reset your password

- -

- We cannot simply send you your old password. A unique link to reset your - password has been generated for you. To reset your password, click the - following link and follow the instructions. -

- Reset - Password - -

- Facing any issue? Write us at -

info@cantileverlabs.com

-logo -

- Privacy Policy -Terms Of Use -Contact Us -

-

-
 
-
 
-
- - copyright 2018 Cantilever Labs -
-
 
-
- - - - - `, // design html for email message. - }; - transport.sendMail(message, function (err, info) { - if (err) { - console.log(err); - } else { - console.log(info); - } - }); - res.status(200).json({ - message: "Link is Active for 10 mins", - reset_link, - }); - }) - .catch((err) => { - console.log(err); - }); - } - }); - } catch { - (error) => { - console.log("Error from forgot pass", error); - }; - } -}; -module.exports.resetpassword = async (req, res, next) => { - const { _id, token } = req.params; - const { password } = req.body; - try { - let user = await User.findById({ _id }); - if (!user) { - res.json({ error: "User not Found or WrongId" }); - return; - } else { - const secret = JWT_secret + user.password; - const user_token = user.passwordResetToken; - const payload = jwt.verify(token, secret); - const hashedPass = await bcrypt.hash(password, 12); - if (token == user_token) { - user.password = hashedPass; - await user - .save() - .then((ok) => { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "*"); - res.json({ message: "Password Updated!" }); - }) - .catch((err) => { - console.log("Error in save", err); - }); - } else { - res.status(422).json({ error: "Either Token not found or Expired!" }); - return; - } - } - } catch { - (err) => { - console.log("error from try catch resetpass", err); - }; - } -}; - -// Forgot password Ends - -// Email verification Ends - -// ----------------------------------------------------------------------------------------------- - -module.exports.checkProtected = (req, res, next) => { - console.log(req.user); - res.json({ - message: "Protected", - user: req.user, - }); -}; diff --git a/.history/controllers/auth_20210519123339.js b/.history/controllers/auth_20210519123339.js deleted file mode 100644 index 675a180..0000000 --- a/.history/controllers/auth_20210519123339.js +++ /dev/null @@ -1,405 +0,0 @@ -const bcrypt = require("bcryptjs"); -const User = require("../models/User"); -const Student = require("../models/Student"); -const jwt = require("jsonwebtoken"); -const JWT_secret = "Cantileverlabs"; -const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS", null, [ - "ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX", -]); -const nodemailer = require("nodemailer"); -const smtpTransport = require("nodemailer-smtp-transport"); - -// -------------------------------------------- mail transporter ----------------------------------------- - -var transport = nodemailer.createTransport( - smtpTransport({ - host: `${process.env.HOST}`, //`${process.env.HOST}` - port: 465, - auth: { - user: `${process.env.EMAIL}`, //`${process.env.EMAIL}` - pass: `${process.env.PASS}`, //`${process.env.PASS}` - }, - }) -); - -// -------------------------------------------- mail transporter ----------------------------------------- - -module.exports.Protected = async (req, res, next) => { - res.send("Hello User"); -}; -module.exports.postSignup = async (req, res, next) => { - try { - //we need firstName , lastName , email , password as input - let firstName = req.body.firstName || " "; - let lastName = req.body.lastName || " "; - const { sending_company_email, email, password, subject } = req.body; - let user = await User.findOne({ email: email }); - if (user) { - res.json({ - message: "User already exist", - type: "error", - }); - } else { - const email_otp = Math.floor(100000 + Math.random() * 900000); - console.log("otp", email_otp); - const hashedPass = await bcrypt.hash(password, 12); - user = new User({ - firstName: firstName, - lastName: lastName, - email: email, - password: hashedPass, - isAdmin: false, - // email_otp, - }); - user = await user.save(); - await Student.deleteOne({ user: user._id }); - let student = new Student({ - user: user._id, - }); - student = await student.save(); - user.student = student._id; - await user.save(); - // const message = { - // from: `${sending_company_email}`, // Sender address - // to: `${email}`, // List of recipients - // subject: `${subject}`, // Subject line - // html: '', // design html for email message. - // }; - // transport.sendMail(message, function (err, info) { - // if (err) { - // console.log(err); - // } else { - // console.log(info); - // } - // }); - res.json({ - message: "You Are Registered, Please Login", - type: "success", - }); - } - } catch (err) { - console.log(err); - } -}; - -module.exports.verfiyemail = async (req, res, next) => { - const { email, otp } = req.body; - try { - let user = await User.findOne({ email: email }); - if (user) { - const isMatched = await (user.email_otp == otp ? true : false); - if (isMatched) { - if (!user.isVerified) { - user.isVerified = true; - await user.save(); - res.json({ - message: "User Verified, Please Login", - }); - } else { - res.json({ - message: "User Already Verified, Please Login", - }); - } - } else { - res.json({ - message: "OTP Doesn't Matched!", - type: "error", - }); - } - } else { - res.json({ - message: "No user with this email exists", - type: "error", - }); - } - } catch { - (err) => { - console.log(err); - }; - } -}; - -module.exports.postSignin = async (req, res, next) => { - try { - //we need email and password as input - let email = req.body.email; - let password = req.body.password; - let user = await User.findOne({ email: email }); - if (user) { - const isMatched = await bcrypt.compare(password, user.password); - if (isMatched) { - const token = jwt.sign({ _id: user._id }, JWT_secret); - res.json({ - token: token, - }); - } else { - res.json({ - message: "email and password doesn't match", - type: "error", - }); - } - } else { - res.json({ - message: "No user with this email exists", - type: "error", - }); - } - } catch (err) { - console.log(err); - } -}; - -// Phone verification Starts. -// ----------------------------------------------------------------------------------------------- - -module.exports.sendOTP = (req, res, next) => { - //uNNYosMopvvCW9RTR1tRWJmYC test - //llVKD53ve6QRpbCKOHzWBADaS live - const { phoneNumber } = req.body; - try { - if (!phoneNumber) { - res.status(422).json({ message: "Please Add All Required Fields" }); - return; - } else { - messagebird.verify.create( - phoneNumber, - { - template: "Your verification code is %token", - }, - function (err, response) { - if (err) { - console.log(err); - res.status(422).json({ message: err.errors[0].description }); - } else { - console.log(response); - res.json({ id: response.id }); - } - } - ); - } - } catch (err) { - console.log(err); - } -}; - -module.exports.getOTP = (req, res, next) => { - try { - const { id, otp } = req.body; - messagebird.verify.verify(id, otp, function (err, response) { - if (err) { - console.log({ error: err.errors[0].description, id: id }); - res.json({ error: err.errors[0].description, id: id }); - } else { - console.log(response); - res.json({ message: "Code Verified" }); - } - }); - } catch (err) { - console.log(err); - } -}; -// Phone verification End. -// ----------------------------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------------------------- -// Forgot password Starts - -module.exports.forgotpassword = async (req, res, next) => { - const { email, link, sending_company_email, subject } = req.body; - //link = https://cantileverlabs.herokuapp.com/resetpassword/:id/:token - try { - await User.findOne({ email }).then((user) => { - if (!user) { - res.status(404).json({ error: "User not found with this Email" }); - return; - } else { - const payload = { - email: user.email, - _id: user._id, - }; - const secret = JWT_secret + user.password; - const token = jwt.sign(payload, secret, { expiresIn: "10m" }); - User.findByIdAndUpdate(user._id, { - $set: { passwordResetToken: token }, - }) - .then((data) => { - const reset_link = `${link}/${user._id}/${token}`; - const message = { - from: `${sending_company_email}`, // Sender address - to: `${user.email}`, // List of recipients - subject: `${subject}`, // Subject line - html: ` - - - - - - Reset Password Email Template - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
 
- -
 
- - - - - - - - - - -
 
- - logo -

You have - requested to reset your password

- -

- We cannot simply send you your old password. A unique link to reset your - password has been generated for you. To reset your password, click the - following link and follow the instructions. -

- Reset - Password - -

- Facing any issue? Write us at -

info@cantileverlabs.com

-logo - -

- Privacy Policy -Terms Of Use -Contact Us -

-

-
 
-
 
-
- - copyright 2018 Cantilever Labs -
-
 
-
- - - - - `, // design html for email message. - }; - transport.sendMail(message, function (err, info) { - if (err) { - console.log(err); - } else { - console.log(info); - } - }); - res.status(200).json({ - message: "Link is Active for 10 mins", - reset_link, - }); - }) - .catch((err) => { - console.log(err); - }); - } - }); - } catch { - (error) => { - console.log("Error from forgot pass", error); - }; - } -}; -module.exports.resetpassword = async (req, res, next) => { - const { _id, token } = req.params; - const { password } = req.body; - try { - let user = await User.findById({ _id }); - if (!user) { - res.json({ error: "User not Found or WrongId" }); - return; - } else { - const secret = JWT_secret + user.password; - const user_token = user.passwordResetToken; - const payload = jwt.verify(token, secret); - const hashedPass = await bcrypt.hash(password, 12); - if (token == user_token) { - user.password = hashedPass; - await user - .save() - .then((ok) => { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "*"); - res.json({ message: "Password Updated!" }); - }) - .catch((err) => { - console.log("Error in save", err); - }); - } else { - res.status(422).json({ error: "Either Token not found or Expired!" }); - return; - } - } - } catch { - (err) => { - console.log("error from try catch resetpass", err); - }; - } -}; - -// Forgot password Ends - -// Email verification Ends - -// ----------------------------------------------------------------------------------------------- - -module.exports.checkProtected = (req, res, next) => { - console.log(req.user); - res.json({ - message: "Protected", - user: req.user, - }); -}; From a53a67c9a4544c7697d9f584ac293a1a8b6a480c Mon Sep 17 00:00:00 2001 From: hardcodder Date: Wed, 19 May 2021 14:51:31 +0530 Subject: [PATCH 4/5] Production razorpay keys --- controllers/payment.js | 4 ++-- nodemon.json | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/payment.js b/controllers/payment.js index 555dbf5..57ff4fa 100644 --- a/controllers/payment.js +++ b/controllers/payment.js @@ -9,8 +9,8 @@ const { getAllCoupons } = require('./coupon'); //test credentials of razorpay const instance = new razorpay({ - key_id : 'rzp_test_tLx9c6GiWjKcsl' , - key_secret : '4Cf52d6C3amkptdRLCTdC2sT' + key_id : process.env.KEY_ID , + key_secret : process.env.KEY_SECRET }) ; module.exports.postVerify =async (req , res , next) => { diff --git a/nodemon.json b/nodemon.json index 4a040aa..3eff58c 100644 --- a/nodemon.json +++ b/nodemon.json @@ -2,6 +2,11 @@ "env" : { "MONGO_USER":"Cantilever", "MONGO_PASSWORD" :"Cantilever" , - "MONGO_DEFAULT_DATABASE" :"myFirstDatabase" + "MONGO_DEFAULT_DATABASE" :"myFirstDatabase" , + "KEY_ID" : "rzp_live_aD9j5WLBGtdQxt" , + "KEY_SECRET" : "o9BDCwYcpNcHyFL5yjiY7OWG" , + "EMAIL" : "AKIA2G7743RRTZMVXE3X" , + "HOST" : "email-smtp.us-east-1.amazonaws.com" , + "PASS" : "BJSjV3jArJfsnk1LhFc/hUmisEyEtbLNGgrRbv0noh8c" } } \ No newline at end of file From 2b0d546ccab1fe95ff71e8211b698692b9fba9d0 Mon Sep 17 00:00:00 2001 From: yashraj verma Date: Sat, 22 May 2021 21:49:46 +0530 Subject: [PATCH 5/5] Update readme.md Done Documentation --- readme.md | 310 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 309 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index f4e21bf..f9ad739 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,309 @@ -Cantileverlabs Nodejs Backend API Documentation. +# Cantileverlabs Nodejs Backend API Documentation. +## Project Structure : + ``` + /root + |- controllers + | |-- admin.js + | |-- auth.js + | |-- blog.js + | |-- coupon.js + | |-- course.js + | |-- payment.js + | |-- profile.js + | |-- query.js + | + |- middlewares + | |-- isAdmin.js + | |-- requireLogin.js + | + |- models + | |-- Blog.js + | |-- Coupon.js + | |-- Course.js + | |-- CourseType.js + | |-- Order.js + | |-- query.js + | |-- Student.js + | |-- User.js + | + |- routes + | |-- admin.js + | |-- auth.js + | |-- blog.js + | |-- Coupon.js + | |-- course.js + | |-- payment.js + | |-- profile.js + | |-- query.js + | + |- app.js + ``` + ### App will listen on the port `http://localhost:5000` + + # Routes Functions and Body Parameters. + + ## File :- Admin.js + + ``` + Route : /addSchedule + Method: POST + Requirements : |-- isAuth + |-- isAdmin + + Route : /editSchedule + Method: POST + Requirements : |-- isAuth + |-- isAdmin + + Route : /deleteSchedule + Method: POST + Requirements : |-- isAuth + |-- isAdmin + +``` + + ## File :- Auth.js + ### Note: `All the Body Params are as it is` + + ``` + Route : /protected + Method: GET + Requirements : |-- isAuth + + + Route : /signup + Method: POST + Body Params :- firstName + - lastName + - email *must* + - password *must* + ---------- for sending the Verification Emial to user. + - sending_company_email + - subject + Response : { + message:"You are Registered, Please Login" + } + Response if email verification: { + message:"Email sent with 6 Digit OTP , Check your Email" + } + + Route : /verifyemail + Method: POST + Body Params: - otp + + Route : /signin + Method: POST + Body Params : - email + - password + + Route : /sendotp + Method: POST + Body Params : phoneNumber + Respone : {id:id} id of the transaction. + + Route : /getotp + Method: POST + Body Params : id , otp + Response : {message:"Code Verified"} + + Route : /forgotpassword + Method: POST + Body Params : email,link,sending_company_email,subject. + + { - email of the user. } + { - link is where to send the user for resetting a password. } + { - sending_company_email is email address of the comapny to send the email to the user. } + { - subject is email subject } + + Route : /resetpassword/:_id/:token + Method: POST + Headers Params : _id, token + Body Params : password + Response : {message:"Password Updated!"} + +``` + + ## File :- BLog.js + + ``` + Route : /addBlog + Method: POST + Body Params : _id , title , body , author , image + + String : { _id : Database _id of a person who is adding up a blog} + String : { title : title of the blog} + String: { body : body of the blog} + String: image of the blog to be added} + String : Author of the blog} + + + Route : /getAllBlogs + Method: GET + Body Params : none + + Route : /deleteBlog + Method: POST + Body Params : _id * must * + + { _id : _id is a id of the blog to delete.} + + Route : /editBlog + Method: POST + Body Params : _id * must * , body , title , image. + + String : { _id : Database _id of a person who is adding up a blog} + String : { title : title of the blog} + String: { body : body of the blog} + String: image of the blog to be added} + +``` + + ## File :- Coupon.js + + ``` + Route : /set-coupon + Method: POST + Body Params : percentage , coupon_code , remainingTimes + + String : { couponCode : Coupon code of the coupon} + String: { percentage: Discount percentage of the coupon} + String: { numAllowed : No of times the coupon is allwoed} + + Route : /getAllCoupons + Method: GET + Body Params : none + + Route : /deleteCoupon + Method: POST + Requirements : isAdmin, isAuth + Body Params : couponCode * must * + + { couponCode : coupon code of the coupon } + + Route : /addCoupon + Method: POST + Requirements : isAdmin, isAuth + Body Params : couponCode * must * , percentage , numAllowed + + String : { couponCode : Coupon code of the coupon} + String: { percentage: Discount percentage of the coupon} + String: { numAllowed : No of times the coupon is allwoed} + +``` + +## File Course.js + +``` + Route : /addCourse + Method : POST + Requirements : isAdmin , isAuth + Body Params : name , mentor , totalLectures , route + + Route : /getAllCourse + Method : GET + Requirements : None + Body Params : None + + + Route : /getSingleParCourse + Method : POST + Body Params : parCourseId + + + Route : /getMeetSchedule + Method : POST + Requiremnents : isAuth + Body Params : courseId + + + Route : /getFromRoute + Method : GET + Requirements : None + Query Params : route + + + Route : /addClick + Method : POST + Requiremnts : isAuth + Body Params : route , userId + + ``` + + ## File Payments.js + + ``` + + Route : /verification + Method : POST + Requirements : None + Body Params : + + + Route : /razorpay + Method : POST + Requirements : requireLogin + Body Params : courseId , couponCode + + ``` + + + ## File Profle.js + + ``` + Route : getProfile + Method : GET + Requirements : requireLogin + Body Params : _id of the User. + + + Route : postProfile + Method : POST + Requirements : requireLogin + Body Params : _id , interests , projects , yearofgrad , phoneNumber , institute , skills + + Route : deleteUser + Method : POST + Requirements : requireLogin + Body Params : _id + {_id : _id of the User to delete the Profile} + + + Route : editUser + Method : POST + Requirements : requireLogin + Body Params : _id , newFirstName , newLastName ,email + + {_id : _id of the user to edit the profile} + {newFirstName : New Name } + {newLastName : New last name} + {email : if email has to be changed} + +``` + + + +## File Query.js + +``` + Route : addQuery + Method : POST + Requirements : None + Body Params : fullName , phoneNumber , email , query , other , graduationYear + + + Route : getAllQueries + Method : GET + Requirements : None + Body Params : None + + + Route : getOtherQueries + Method : GET + Requirements : None + Body Params : None + + + Route : getTypeQueries + Method : POST + Requirements : None + Body Params : type