Push Emails Added
This commit is contained in:
parent
f9a018de8d
commit
6665eb761f
|
@ -4,6 +4,7 @@ const Student = require("../models/Student");
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
const JWT_secret = "Cantileverlabs";
|
const JWT_secret = "Cantileverlabs";
|
||||||
const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS");
|
const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS");
|
||||||
|
const nodemailer = require("nodemailer");
|
||||||
|
|
||||||
module.exports.Protected = async (req, res, next) => {
|
module.exports.Protected = async (req, res, next) => {
|
||||||
res.send("Hello User");
|
res.send("Hello User");
|
||||||
|
@ -124,11 +125,18 @@ module.exports.getOTP = (req, res, next) => {
|
||||||
console.log(err);
|
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) => {
|
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 {
|
try {
|
||||||
await User.findOne({ email }).then((user) => {
|
await User.findOne({ email }).then((user) => {
|
||||||
console.log("user before", user);
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(404).json({ error: "User not found with this Email" });
|
res.status(404).json({ error: "User not found with this Email" });
|
||||||
return;
|
return;
|
||||||
|
@ -144,6 +152,19 @@ module.exports.forgotpassword = async (req, res, next) => {
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const reset_link = `${link}/${user._id}/${token}`;
|
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({
|
res.status(200).json({
|
||||||
message: "Token Saved and link is active for 10 mins",
|
message: "Token Saved and link is active for 10 mins",
|
||||||
reset_link,
|
reset_link,
|
||||||
|
@ -152,8 +173,6 @@ module.exports.forgotpassword = async (req, res, next) => {
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("user after", user);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -17,4 +17,6 @@ router.post("/forgotpassword", authController.forgotpassword);
|
||||||
|
|
||||||
router.post("/resetpassword/:_id/:token", authController.resetpassword);
|
router.post("/resetpassword/:_id/:token", authController.resetpassword);
|
||||||
|
|
||||||
|
router.get("/resetpassword/:_id/:token", authController.resetpassword);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
Loading…
Reference in New Issue