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) {
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
.
get
(
'
/
'
,
function
(
req
,
res
)
{
res
.
redirect
(
'
/profile
'
)
...
...
@@ -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: 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
"
+
"
Thanks,
\n
M4_LAB Team
"
...
...
@@ -395,7 +407,7 @@ module.exports = function (app, config, passport) {
});
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
)
{
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
.
check
UserToken
(
req
.
params
.
token
,
function
(
err
,
user
){
methods
.
get
User
By
Token
(
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
}
})
});
...
...
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