Commit eb68b4cb authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

email notification after update/reset password

parent cddaca29
...@@ -107,6 +107,11 @@ module.exports = function (app, config, passport) { ...@@ -107,6 +107,11 @@ module.exports = function (app, config, passport) {
text: "" text: ""
}; };
var updatePasswordMailContent = "Hello,\n\n"+
"We would like to notify that your password has been successfully updated.\n\n"+
"Thanks,\nM4_LAB Team"
var updatePasswordMailSubject = "Your M4_LAB Password has been updated"
// ======== APP ROUTES ==================== // ======== APP ROUTES ====================
app.get('/', function (req, res) { app.get('/', function (req, res) {
res.redirect('/profile') res.redirect('/profile')
...@@ -310,7 +315,14 @@ module.exports = function (app, config, passport) { ...@@ -310,7 +315,14 @@ module.exports = function (app, config, passport) {
} }
else { else {
req.flash('success', "Pasword updated!") req.flash('success', "Pasword updated!")
console.log('pasword updated!') mailOptions.to = req.user.email
mailOptions.subject = "Your M4_LAB Password has been updated"
mailOptions.text = updatePasswordMailContent
smtpTransport.sendMail(mailOptions, function(err) {
if (err) {
console.log(err)
}
});
} }
res.redirect('/security') res.redirect('/security')
}) })
...@@ -357,7 +369,7 @@ module.exports = function (app, config, passport) { ...@@ -357,7 +369,7 @@ module.exports = function (app, config, passport) {
emailSubject = "M4_LAB Password Reset"; emailSubject = "M4_LAB Password Reset";
emailContent = "Hi User,\n\n"+ emailContent = "Hi User,\n\n"+
"we've received a request to reset your password. If you didn't make the request, just ignore this email.\n\n"+ "we've received a request to reset your password. If you didn't make the request, just ignore this email.\n\n"+
"Otherwise, you can reset your password using this link: https://" + config.app.hostname + "/reset/" + token + "\n" + "Otherwise, you can reset your password using this link: http://localhost:9989/reset/" + token + "\n" +
"This password reset is only valid for 1 hour.\n\n"+ "This password reset is only valid for 1 hour.\n\n"+
"Thanks,\nM4_LAB Team" "Thanks,\nM4_LAB Team"
...@@ -395,7 +407,7 @@ module.exports = function (app, config, passport) { ...@@ -395,7 +407,7 @@ module.exports = function (app, config, passport) {
}); });
app.get('/reset/:token', function(req, res) { app.get('/reset/:token', function(req, res) {
methods.checkUserToken(req.params.token, function(err, user){ methods.getUserByToken(req.params.token, function(err, user){
if (!user) { if (!user) {
req.flash('error', 'Password reset token is invalid or has expired.'); req.flash('error', 'Password reset token is invalid or has expired.');
res.redirect('/forgotPwd'); res.redirect('/forgotPwd');
...@@ -408,7 +420,7 @@ module.exports = function (app, config, passport) { ...@@ -408,7 +420,7 @@ module.exports = function (app, config, passport) {
app.post('/reset/:token', function(req, res) { app.post('/reset/:token', function(req, res) {
var newPwd = req.body.inputNewPwd var newPwd = req.body.inputNewPwd
methods.checkUserToken(req.params.token, function(err, user){ methods.getUserByToken(req.params.token, function(err, user){
if (user) { if (user) {
// encrypt password // encrypt password
bcrypt.genSalt(saltRounds, function(err, salt) { bcrypt.genSalt(saltRounds, function(err, salt) {
...@@ -425,9 +437,17 @@ module.exports = function (app, config, passport) { ...@@ -425,9 +437,17 @@ module.exports = function (app, config, passport) {
} }
else { else {
req.flash('success', "Your pasword has been updated.") req.flash('success', "Your pasword has been updated.")
console.log('pasword updated!') // send notifiaction email
mailOptions.to = user.email
mailOptions.subject = updatePasswordMailSubject
mailOptions.text = updatePasswordMailContent
smtpTransport.sendMail(mailOptions, function(err) {
if (err) {
console.log(err)
}
});
// redirect to login page
res.redirect('/login') res.redirect('/login')
// todo: send confirmation email
} }
}) })
}); });
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment