From f1c5ba4b2bdaacbacbf7e1bca5a39d973d077d13 Mon Sep 17 00:00:00 2001 From: yashraj verma Date: Wed, 12 May 2021 17:18:25 +0530 Subject: [PATCH 1/6] Push Emails added --- controllers/auth.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/controllers/auth.js b/controllers/auth.js index 807b04e..92e390f 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -79,6 +79,9 @@ module.exports.postSignin = async (req, res, next) => { } }; +// Phone verification Starts. +// ----------------------------------------------------------------------------------------------- + module.exports.sendOTP = (req, res, next) => { //uNNYosMopvvCW9RTR1tRWJmYC test //llVKD53ve6QRpbCKOHzWBADaS live @@ -111,8 +114,8 @@ module.exports.sendOTP = (req, res, next) => { module.exports.getOTP = (req, res, next) => { try { - const { id, token } = req.body; - messagebird.verify.verify(id, token, function (err, response) { + 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 }); @@ -125,16 +128,22 @@ module.exports.getOTP = (req, res, next) => { console.log(err); } }; +// Phone verification End. +// ----------------------------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------------------------- +// Email verification Starts + var transport = nodemailer.createTransport({ - host: "smtp.mailtrap.io", - port: 2525, + service: "gmail", auth: { - user: "5578544cc56856", - pass: "a510d3d969d3b3", + 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; //link = https://cantileverlabs.herokuapp.com/resetpassword/:id/:token + const { email, link, _html, sending_company_email, subject } = req.body; + //link = https://cantileverlabs.herokuapp.com/resetpassword/:id/:token try { await User.findOne({ email }).then((user) => { if (!user) { @@ -180,7 +189,6 @@ module.exports.forgotpassword = async (req, res, next) => { console.log("Error from forgot pass", error); }; } - //verify email then set password. }; module.exports.resetpassword = async (req, res, next) => { const { _id, token } = req.params; @@ -217,6 +225,9 @@ module.exports.resetpassword = async (req, res, next) => { } }; +// Email verification Ends +// ----------------------------------------------------------------------------------------------- + module.exports.checkProtected = (req, res, next) => { console.log(req.user); res.json({ From ef4c9b6a526e0ef10b94f271654809ce636d8ab0 Mon Sep 17 00:00:00 2001 From: yashraj verma Date: Wed, 12 May 2021 17:19:42 +0530 Subject: [PATCH 2/6] done --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 217a4fa..43635e8 100644 --- a/app.js +++ b/app.js @@ -18,7 +18,7 @@ const cors = require("cors"); const app = express(); -const MONGO_URI = `mongodb+srv://Cantilever:Cantilever@cluster0.dqxva.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`; +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()); From bc90edb1aae7c09e5a7a00d1fcf2532cfb8e2b30 Mon Sep 17 00:00:00 2001 From: yashrajverma Date: Mon, 17 May 2021 15:11:13 +0530 Subject: [PATCH 3/6] Completed --- controllers/auth.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/controllers/auth.js b/controllers/auth.js index 7b99380..d6558d0 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -254,10 +254,7 @@ module.exports.forgotpassword = async (req, res, next) => { - - logo - + @@ -272,7 +269,10 @@ module.exports.forgotpassword = async (req, res, next) => { -

You have + + logo +

You have requested to reset your password

@@ -282,8 +282,20 @@ module.exports.forgotpassword = async (req, res, next) => { following link and follow the instructions.

Reset + style="background:#ffc600;text-decoration:none !important; font-weight:500; margin-top:35px; color:#111;text-transform:uppercase; font-size:14px;padding:10px 24px;display:inline-block;border-radius:50px;">Reset Password + +

+ Facing any issue? Write us at +

info@cantileverlabs.com

+logo +

+ Privacy Policy +Terms Of Use +Contact Us +

+

@@ -302,6 +314,7 @@ module.exports.forgotpassword = async (req, res, next) => { +   From 7151cba2c42f34ca528f12133ce617dc85756ad9 Mon Sep 17 00:00:00 2001 From: yashrajverma Date: Wed, 19 May 2021 12:22:26 +0530 Subject: [PATCH 4/6] Added Blog Backend --- app.js | 8 ++-- controllers/auth.js | 11 +++-- controllers/blog.js | 103 ++++++++++++++++++++++++++++++++++++++++ controllers/coupon.js | 106 +++++++++++++++++++----------------------- models/Blog.js | 27 +++++++++++ routes/blog.js | 14 ++++++ 6 files changed, 202 insertions(+), 67 deletions(-) create mode 100644 controllers/blog.js create mode 100644 models/Blog.js create mode 100644 routes/blog.js diff --git a/app.js b/app.js index 43635e8..b02365d 100644 --- a/app.js +++ b/app.js @@ -8,21 +8,19 @@ 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 app = express(); - 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()); -require("./models/Coupon"); // app.use(cookieSession({ // name: 'test-session', @@ -104,4 +102,6 @@ app.use(adminRoute); app.use(couponRoute); +app.use(blogRouter); + app.use(queryRoute); diff --git a/controllers/auth.js b/controllers/auth.js index d6558d0..9f37047 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -13,11 +13,11 @@ const smtpTransport = require("nodemailer-smtp-transport"); var transport = nodemailer.createTransport( smtpTransport({ - host: `${process.env.HOST}`, //`${process.env.HOST}` + host: `email-smtp.us-east-1.amazonaws.com`, //`${process.env.HOST}` port: 465, auth: { - user: `${process.env.EMAIL}`, //`${process.env.EMAIL}` - pass: `${process.env.PASS}`, //`${process.env.PASS}` + user: `AKIA2G7743RRTZMVXE3X`, //`${process.env.EMAIL}` + pass: `BJSjV3jArJfsnk1LhFc/hUmisEyEtbLNGgrRbv0noh8c`, //`${process.env.PASS}` }, }) ); @@ -289,7 +289,8 @@ module.exports.forgotpassword = async (req, res, next) => { Facing any issue? Write us at

info@cantileverlabs.com

logo + src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcIAAABwCAMAAAC6s4C9AAABgFBMVEX///9YWFr+/v5YWFhWVlhISEj7+/sAAABQUFKcnJ7IyMhUVFRKSkpTU1VQUFD4+Pjd3d1qamqsrKx8fHzw8PCSkpTy8vLW1ta7u73p6emXl5dISEpkZGSCgoLBwcEiICFzc3PQ0NAcGhuJiYn///r4//9eXl6kpKQnJSaqqqoVExQLAAD/+v9BQUE8PDwPDA3t/////fIAW6QAXJwAU5YzMzMnHyL/qyf/+s7/qRQAW6v/sAAaGhdqZGfk+f/V7fN0mLUvY5ERVohdiKPA4e4hUnoAT4oASnuev9AAP3MYFx27y9UAQISBlKsARpUAXJhZfJsSDBYAVKaXttQAN3IAO4L/8M7x26Ht25GvzeBQR1drcmPjsEnjrhTeszT056fzsCn97pbvvDkUABEWFQj88cAoJBo3PC3a3s9OP0n/qTF4doHuy3XgoynqumT8uQDetADt2HvnrU5AZ4bryXv//uUBABUXGAD56Mvv1a5nXG8WDyzixVDfuGjsqj0gERIXE4LXAAAbTUlEQVR4nO1dC2PbxpFeLskFRYBYgARBgk/wAVCiSMm0ZVmyHKe5tHm4vkvTtHbS2ol6iXO95qE2ta/Xu17y129mF+BDBChRsmOpwedEAonFvr6d2ZnZXYiQBAkSJEiQIEGCBAkSJEiQIEGCBAkS/HigjFL2uiuR4FKgjNHXXYcElwJ3SELhtQY1FeN11yHBxcEpd5XudsLh9QUyuNkdVl53PRJcGMBge9hOGLy2oMRU2t1NgyfmzPUEeIMNkMHNCqjT112XBBeCkME2zIMs8eyvKVgDLJmugZ59okiv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QupesyODFMFd2nwx8G3atO0JHgkWOWQewNJcOROhFXEI046DG5M04oKBNv55h4PKxdG8mS5MtjGdFEXyuZSMkLZfPly42EQq5PLLK9g8eKqA7upVspXOu7Sm6/yeqtSqWmr3iy4CGarg0qlqEWfHlirVkDXePUfpkgwA4zeDkyKS4cfQJwGzVL1/L2IEt1qNjfWO+cXlxff4P+UOvHlg07/QtBSh/FwWfi8WTF53P1lSI9cjPjJ6cSLYbplPGKHtZhA18mKTae0S1eLXLEwZYIECRIkSJAgQYIECRIkSJAgQYIECRIkSJAgQYIECRIkSJBgLfw/Hmu6adIWw+0AAAAASUVORK5CYII=" + title="logo" alt="logo">

Privacy Policy Terms Of Use @@ -369,6 +370,8 @@ module.exports.resetpassword = async (req, res, next) => { await user .save() .then((ok) => { + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "*"); res.json({ message: "Password Updated!" }); }) .catch((err) => { diff --git a/controllers/blog.js b/controllers/blog.js new file mode 100644 index 0000000..f6ea6c1 --- /dev/null +++ b/controllers/blog.js @@ -0,0 +1,103 @@ +const { log } = require("handlebars"); +const Blog = require("../models/Blog"); +const Course = require("../models/Course"); + +module.exports.getAllBlogs = async (req, res, next) => { + try { + let blog = await Blog.find(); + if (blog) { + res.json({ blogs: blog }); + } else { + console.log("Error in Blog", blog); + return; + } + } catch { + (err) => { + res.status(422).json({ error: err }); + }; + } +}; + +module.exports.addBlog = async (req, res, next) => { + const { _id, title, body, image } = req.body; //_id is of user from frontend who is adding the blog. + try { + let course = await Course.find({ _id }); + if (!title) { + res.status(422).json({ message: "Please, Add Title of the Blog" }); + return; + } + if (!body) { + res.status(422).json({ message: "Please, Add Body of the Blog" }); + return; + } + if (course) { + let blog = new Blog({ + title, + body, + image, + date: new Date(), + }); + await blog.save(); + res.json({ message: "Blog Saved Successfully!" }); + } else { + res.status.json({ error: "User Doesn't Exists" }); + return; + } + } catch { + (err) => { + res.status(422).json({ error: err }); + }; + } +}; + +module.exports.deleteBlog = async (req, res, next) => { + const { _id } = req.body; + try { + let blog = await Blog.find({ _id }); + if (blog) { + await Blog.findByIdAndDelete(_id); + res.json({ message: "Blog Deleted!" }); + } else { + res.status(404).json({ message: "Blog Not Found" }); + return; + } + } catch { + (err) => { + res.status(422).json({ error: err }); + }; + } +}; + +module.exports.editBlog = async (req, res, next) => { + const { _id, body, title, image } = req.body; + + try { + if (!title) { + res.status(422).json({ message: "Please, Add the Title of the Blog." }); + return; + } + if (!body) { + res.status(422).json({ message: "Please, Add the Body of the Blog." }); + return; + } + if (!image) { + res.status(422).json({ message: "Please, Add the Image of the Blog." }); + return; + } + let blog = Blog.findById(_id); + if (blog) { + blog.title = title; + blog.body = body; + blog.image = image; + await blog.save(); + res.json({ message: "Blog Updated!" }); + } else { + res.status(422).json({ error: "Blog Doesn't Found" }); + return; + } + } catch { + (err) => { + res.status(422).json({ error: err }); + }; + } +}; diff --git a/controllers/coupon.js b/controllers/coupon.js index 2220624..238e1ed 100644 --- a/controllers/coupon.js +++ b/controllers/coupon.js @@ -1,64 +1,52 @@ const Coupon = require("../models/Coupon"); -module.exports.getAllCoupons = async (req , res , next) => { - try - { - const coupons = await Coupon.find() ; - console.log(coupons) ; - res.json({ - coupons : coupons - }) ; - } - catch(err) - { - console.log(err) ; - } -} +module.exports.getAllCoupons = async (req, res, next) => { + try { + const coupons = await Coupon.find(); + console.log(coupons); + res.json({ + coupons: coupons, + }); + } catch (err) { + console.log(err); + } +}; -module.exports.addCoupon = async (req , res , next) => { - try - { - const couponCode = req.body.couponCode ; - const percentage = req.body.percentage ; - const numAllowed = req.body.numAllowed ; - - let coupon = await Coupon.findOne({couponCode : couponCode}) ; - if(coupon) - { - res.json({ - error:"coupon already Exist" - }) - } - else - { - let coupon = new Coupon({ - couponCode : couponCode , - percentage : percentage , - numAllowed : numAllowed - }) ; - coupon = await coupon.save() ; - res.json({ - message: "Created Successfully" - }) - } - } - catch(err) - { - console.log(err); - } -} +module.exports.addCoupon = async (req, res, next) => { + try { + const couponCode = req.body.couponCode; + const percentage = req.body.percentage; + const numAllowed = req.body.numAllowed; -module.exports.deleteCoupon = async (req , res, next) => { - try - { - const couponCode = req.body.couponCode ; - await Coupon.deleteOne({couponCode : couponCode}) ; - res.json({ - message: "Deleted Successfully" - }) + let coupon = await Coupon.findOne({ couponCode: couponCode }); + if (coupon) { + res.json({ + error: "Coupon already Exist", + }); + } else { + let coupon = new Coupon({ + couponCode: couponCode, + percentage: percentage, + numAllowed: numAllowed, + }); + coupon = await coupon.save(); + res.json({ + message: "Created Successfully", + }); } - catch(err) - { - console.log(err); - } -} \ No newline at end of file + } catch (err) { + console.log(err); + } +}; + +module.exports.deleteCoupon = async (req, res, next) => { + try { + const couponCode = req.body.couponCode; + await Coupon.deleteOne({ couponCode: couponCode }); + res.json({ + message: "Deleted Successfully", + }); + } catch (err) { + console.log(err); + } +}; diff --git a/models/Blog.js b/models/Blog.js new file mode 100644 index 0000000..33e6c55 --- /dev/null +++ b/models/Blog.js @@ -0,0 +1,27 @@ +const mongoose = require("mongoose"); +const blogSchema = new mongoose.Schema({ + title: { + type: String, + require: true, + }, + author: { + type: String, + ref: "Course", + }, + date: { + type: Date, + }, + image: { + type: String, + default: "", + }, + body: { + type: String, + required: true, + }, + isBookMarked: { + type: Boolean, + default: false, + }, +}); +module.exports = mongoose.model("Blog", blogSchema); diff --git a/routes/blog.js b/routes/blog.js new file mode 100644 index 0000000..51e5d57 --- /dev/null +++ b/routes/blog.js @@ -0,0 +1,14 @@ +const express = require("express"); +const router = express.Router(); +const BlogController = require("../controllers/blog"); +const isAuth = require("../middleware/requirelogin"); + +router.post("/add-blog", BlogController.addBlog); + +router.get("/get-all-blogs", BlogController.getAllBlogs); + +router.post("/delete-blog/", isAuth, BlogController.deleteBlog); + +router.post("/edit-blog/", isAuth, BlogController.editBlog); + +module.exports = router; From 45b5a2eade9bf72378722f0b8ebeb086e83b8df6 Mon Sep 17 00:00:00 2001 From: yashrajverma Date: Wed, 19 May 2021 12:34:12 +0530 Subject: [PATCH 5/6] Blog Completed --- .history/controllers/auth_20210519123339.js | 405 ++++++++++++++++++++ controllers/auth.js | 6 +- 2 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 .history/controllers/auth_20210519123339.js diff --git a/.history/controllers/auth_20210519123339.js b/.history/controllers/auth_20210519123339.js new file mode 100644 index 0000000..675a180 --- /dev/null +++ b/.history/controllers/auth_20210519123339.js @@ -0,0 +1,405 @@ +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, + }); +}; diff --git a/controllers/auth.js b/controllers/auth.js index 833b8f3..675a180 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -13,11 +13,11 @@ const smtpTransport = require("nodemailer-smtp-transport"); var transport = nodemailer.createTransport( smtpTransport({ - host: `email-smtp.us-east-1.amazonaws.com`, //`${process.env.HOST}` + host: `${process.env.HOST}`, //`${process.env.HOST}` port: 465, auth: { - user: `AKIA2G7743RRTZMVXE3X`, //`${process.env.EMAIL}` - pass: `BJSjV3jArJfsnk1LhFc/hUmisEyEtbLNGgrRbv0noh8c`, //`${process.env.PASS}` + user: `${process.env.EMAIL}`, //`${process.env.EMAIL}` + pass: `${process.env.PASS}`, //`${process.env.PASS}` }, }) ); From d25cc5b42fa5c837c09e52a7869736306c7a378b Mon Sep 17 00:00:00 2001 From: yashraj verma Date: Wed, 19 May 2021 12:38:12 +0530 Subject: [PATCH 6/6] 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, - }); -};