Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
m4lab_tv1
User Account
Commits
eb68b4cb
Commit
eb68b4cb
authored
Dec 17, 2019
by
Rosanny Sihombing
Browse files
email notification after update/reset password
parent
cddaca29
Changes
1
Show whitespace changes
Inline
Side-by-side
routes/routes.js
View file @
eb68b4cb
...
@@ -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,
\n
M4_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: http
s
://
"
+
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,
\n
M4_LAB Team
"
"
Thanks,
\n
M4_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
.
check
UserToken
(
req
.
params
.
token
,
function
(
err
,
user
){
methods
.
get
User
By
Token
(
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
.
check
UserToken
(
req
.
params
.
token
,
function
(
err
,
user
){
methods
.
get
User
By
Token
(
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
}
}
})
})
});
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment