Last active
May 11, 2020 04:07
-
-
Save maneeshaindrachapa/e52e5f9116cad23e13ef44f253f0421e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require('jsonwebtoken'); | |
const nodemailer = require('nodemailer'); | |
var smtpTransport = require('nodemailer-smtp-transport'); | |
const config = require('../../config.json'); | |
const dbConfig = require("../../mysql_connection"); | |
exports.forgetPassword = function (req, res, next) { | |
let email = req.body.email; | |
let query_ = "SELECT * from user where email=?"; | |
dbConfig.query(query_, [email], (err, rows) => { | |
if (err) { | |
console.log("Error Connecting to Server !"); | |
return res.status(404).send({ success: false, message: "Error Connecting to Server!" }); | |
} else { | |
if (rows[0] != null) { | |
let randomNo = Math.floor(100000 + Math.random() * 900000); | |
let transporter = nodemailer.createTransport(smtpTransport({ | |
service: 'gmail', | |
host: 'smtp.gmail.com', | |
auth: { | |
user: 'snykmonitor95@gmail.com', | |
pass: 'Maneesha@123' | |
} | |
})); | |
let mailOptions = { | |
from: 'snykmonitor95@gmail.com', | |
to: email, | |
subject: 'Rest Password of Bellarena Account', | |
text: 'Your Six Digit Token:'+randomNo | |
}; | |
let query_0 = "UPDATE user set forgetPasswordNo=? where email=?"; | |
dbConfig.query(query_0, [randomNo,email], (err, rows) => { | |
if (err) { | |
console.log("Error Connecting to Server !"); | |
console.log(err); | |
return res.status(404).send({ success: false, message: "Error Connecting to Server!" }); | |
} else { | |
transporter.sendMail(mailOptions, function(error, info){ | |
if (error) { | |
return res.status(404).send({ success: false, message: "Error connecting to mail server!" }); | |
} else { | |
res.status(200).send({ success: true, data: { email: email, message: "Successfully send the mail" } }); | |
} | |
}); | |
} | |
}); | |
} else { | |
console.log("Invalid Email address!"); | |
return res.status(401).send({ success: false, message: "Invalid Email address!" }); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment