Skip to content

Commit

Permalink
fixed email change and provised a temporary file for displaying email…
Browse files Browse the repository at this point in the history
… change success
  • Loading branch information
lucakiebel committed Mar 7, 2018
1 parent 5c984d6 commit 1dccce9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1178,15 +1178,18 @@ app.post("/api/user/changeEmail", requireAuthentication, (req, res) => {

app.get("/user/change-email/:id", (req, res) => {
let newEmail = req.query.newEmail;
let resetId = req.body.id;
let resetId = req.params.id;
EmailReset.findOne({_id:resetId}, (err, er) => {
let userId = er.userId;
User.findOne({_id:userId}, (err, user) => {
if (er.expiry.getTime() >= new Date(Date.now()).getTime()) {
if (er.expiry >= Date.now()) {
// not expired
User.findOneAndUpdate(user, {$set: {email: newEmail}}, (err, update) => {
User.update({_id:user._id}, {$set: {email: newEmail}}, (err, update) => {
if (!err) res.render("email-change-end", {success: true});
else res.render("email-change-end", {success: false});
else {
res.render("email-change-end", {success: false});
console.log(update, err)
}
})
}
});
Expand Down
1 change: 1 addition & 0 deletions views/email-change-end.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
email changed <%=success%>

0 comments on commit 1dccce9

Please sign in to comment.