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

email notification after update/reset password

parent cddaca29
......@@ -106,6 +106,11 @@ module.exports = function (app, config, passport) {
subject: "",
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.get('/', function (req, res) {
......@@ -310,7 +315,14 @@ module.exports = function (app, config, passport) {
}
else {
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')
})
......@@ -357,7 +369,7 @@ module.exports = function (app, config, passport) {
emailSubject = "M4_LAB Password Reset";
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"+
"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"+
"Thanks,\nM4_LAB Team"
......@@ -395,7 +407,7 @@ module.exports = function (app, config, passport) {
});
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) {
req.flash('error', 'Password reset token is invalid or has expired.');
res.redirect('/forgotPwd');
......@@ -408,7 +420,7 @@ module.exports = function (app, config, passport) {
app.post('/reset/:token', function(req, res) {
var newPwd = req.body.inputNewPwd
methods.checkUserToken(req.params.token, function(err, user){
methods.getUserByToken(req.params.token, function(err, user){
if (user) {
// encrypt password
bcrypt.genSalt(saltRounds, function(err, salt) {
......@@ -425,9 +437,17 @@ module.exports = function (app, config, passport) {
}
else {
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')
// todo: send confirmation email
}
})
});
......
Markdown is supported
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