Push Emails Added

This commit is contained in:
yashrajverma 2021-05-12 16:14:03 +05:30
parent f9a018de8d
commit 6665eb761f
2 changed files with 25 additions and 4 deletions

View File

@ -4,6 +4,7 @@ const Student = require("../models/Student");
const jwt = require("jsonwebtoken");
const JWT_secret = "Cantileverlabs";
const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS");
const nodemailer = require("nodemailer");
module.exports.Protected = async (req, res, next) => {
res.send("Hello User");
@ -124,11 +125,18 @@ module.exports.getOTP = (req, res, next) => {
console.log(err);
}
};
var transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "5578544cc56856",
pass: "a510d3d969d3b3",
},
});
module.exports.forgotpassword = async (req, res, next) => {
const { email, link } = 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) => {
console.log("user before", user);
if (!user) {
res.status(404).json({ error: "User not found with this Email" });
return;
@ -144,6 +152,19 @@ module.exports.forgotpassword = async (req, res, next) => {
})
.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: `${_html}`, // 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: "Token Saved and link is active for 10 mins",
reset_link,
@ -152,8 +173,6 @@ module.exports.forgotpassword = async (req, res, next) => {
.catch((err) => {
console.log(err);
});
console.log("user after", user);
}
});
} catch {

View File

@ -17,4 +17,6 @@ router.post("/forgotpassword", authController.forgotpassword);
router.post("/resetpassword/:_id/:token", authController.resetpassword);
router.get("/resetpassword/:_id/:token", authController.resetpassword);
module.exports = router;