add unsubscribe path

This commit is contained in:
Quincy Larson
2015-04-30 23:41:40 -07:00
parent c71514cc81
commit 19456f2e23
4 changed files with 46 additions and 0 deletions

10
app.js
View File

@ -514,6 +514,16 @@ app.post(
storyController.upvote
);
app.get(
'/unsubscribe/:email',
resourcesController.unsubscribe
);
app.get(
'/unsubscribed',
resourcesController.unsubscribed
);
app.all('/account', passportConf.isAuthenticated);
app.get('/account/api', userController.getAccountAngular);

View File

@ -185,6 +185,35 @@ module.exports = {
});
},
unsubscribe: function unsubscribe(req, res) {
User.findOne({email: req.params.email}, function(err, user) {
console.log('---------');
console.log(req.params);
console.log('---------');
console.log(user);
if (user) {
if (err) {
return next(err);
}
user.sendMonthlyEmail = false;
user.save(function () {
if (err) {
return next(err);
}
res.redirect('/unsubscribed');
});
} else {
res.redirect('/unsubscribed');
}
});
},
unsubscribed: function unsubscribed(req, res) {
res.render('resources/unsubscribed', {
title: "You have been unsubscribed"
});
},
githubCalls: function(req, res) {
var githubHeaders = {headers: {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'}, port:80 };
request('https://api.github.com/repos/freecodecamp/freecodecamp/pulls?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function(err, status1, pulls) {

View File

@ -141,6 +141,7 @@ var userSchema = new mongoose.Schema({
},
needsMigration: { type: Boolean, default: true },
finishedWaypoints: { type: Boolean, default: false },
sendMonthlyEmail: { type: Boolean, default: true },
challengesHash: {}
});

View File

@ -0,0 +1,6 @@
extends ../layout
block content
.panel.panel-info
.panel-body.text-center
h1 You have successfully been unsubscribed.
h2 Whatever you do, keep coding! :)