Skip to content

Commit

Permalink
Fixed a bug that name and email are still changed if user is demo
Browse files Browse the repository at this point in the history
  • Loading branch information
githubalexliu committed May 21, 2018
1 parent 8033b4a commit 4a66fd4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,30 @@ module.exports = function(app, passport) {
if (req.user.username === 'demo') {
req.flash('messageFail', 'Sorry. You are using a demo account so you cannot \
change your name.');
res.redirect('back');
}
changeName(req.user.id, req.body.firstname, req.body.lastname);
req.flash('messageSuccess', 'Your name has been changed.');
else {
changeName(req.user.id, req.body.firstname, req.body.lastname);
req.flash('messageSuccess', 'Your name has been changed.');
}
res.redirect('back');
});

app.post('/changeemail', function(req, res) {
if (req.user.username === 'demo') {
req.flash('messageFail', 'Sorry. You are using a demo account so you cannot \
change your email.');
res.redirect('back');
}
changeEmail(req.user.id, req.body.email);
req.flash('messageSuccess', 'Your email has been changed.');
else {
changeEmail(req.user.id, req.body.email);
req.flash('messageSuccess', 'Your email has been changed.');
}
res.redirect('back');
});

app.post('/changepw', function(req, res) {
if (req.user.username === 'demo') {
req.flash('messageFail', 'Sorry. You are using a demo account so you cannot \
change your password.');
res.redirect('back');
}
// Is there a way to move this into profile.js?
// If I move the redirect out of connection.query, the messages are not flashed
Expand All @@ -101,9 +102,9 @@ module.exports = function(app, passport) {
req.flash('messageSuccess', 'Your password has been changed. Please \
logout for your new password to take effect.');
}
res.redirect('back');
});
}
res.redirect('back');
});

app.get('/word-list', isLoggedIn, function(req, res) {
Expand Down

0 comments on commit 4a66fd4

Please sign in to comment.