Merge pull request #3514 from FreeCodeCamp/tshirt

Tshirt voting mechanism
This commit is contained in:
Quincy Larson
2015-09-27 11:06:26 -07:00
3 changed files with 63 additions and 1 deletions

View File

@ -157,6 +157,9 @@
"rand": { "rand": {
"type": "number", "type": "number",
"index": true "index": true
},
"tshirtVote": {
"type": "number"
} }
}, },
"validations": [], "validations": [],

View File

@ -76,6 +76,8 @@ module.exports = function(app) {
); );
router.get('/account/unlink/:provider', getOauthUnlink); router.get('/account/unlink/:provider', getOauthUnlink);
router.get('/account', getAccount); router.get('/account', getAccount);
router.get('/vote1', vote1);
router.get('/vote2', vote1);
// Ensure this is the last route! // Ensure this is the last route!
router.get('/:username', returnUser); router.get('/:username', returnUser);
@ -332,4 +334,36 @@ module.exports = function(app) {
}); });
}); });
} }
function vote1(req, res) {
if (req.user) {
req.user.tshirtVote = 1;
req.user.save(function (err) {
if (err) {
return next(err);
}
req.flash('success', {msg: 'Thanks for voting!'});
res.redirect('/map');
});
} else {
req.flash('error', {msg: 'You must be signed in to vote.'});
res.redirect('/map');
}
}
function vote2(req, res) {
if (req.user) {
req.user.tshirtVote = 2;
req.user.save(function (err) {
if (err) {
return next(err);
}
req.flash('success', {msg: 'Thanks for voting!'});
res.redirect('/map');
});
} else {
req.flash('error', {msg: 'You must be signed in to vote.'});
res.redirect('/map');
}
}
}; };

View File

@ -17,7 +17,32 @@ block content
| since we launched   | since we launched  
span.text-primary #{daysRunning}   span.text-primary #{daysRunning}  
| days ago. | days ago.
a.btn.btn-lg.signup-btn.btn-block(href="https://www.facebook.com/sharer/sharer.php?u=http://freecodecamp.com" target='_blank') Share our open source community on Facebook and help us grow. .spacer
if (user && !user.tshirtVote && user.progressTimestamps.length > 5)
h3.text-center Vote for the T-shirt design you like the most.
h4.text-center We'll announce the winning design on Saturday's Summit on Twitch.tv, and it will become our community's first official t-shirt.
.row
.col-xs-6
a(href="http://i.imgur.com/LlXGa5y.png" data-lightbox="img-enlarge")
img.img-responsive(src='http://i.imgur.com/LlXGa5y.png' alt="t-shirt option 1 women's")
.col-xs-6
a(href="http://i.imgur.com/aefwnnv.png" data-lightbox="img-enlarge")
img.img-responsive(src='http://i.imgur.com/aefwnnv.png' alt="t-shirt option 2 women's")
.button-spacer
.row
.col-xs-6
a(href="http://i.imgur.com/aYH0aqf.png" data-lightbox="img-enlarge")
img.img-responsive(src='http://i.imgur.com/aYH0aqf.png' alt="t-shirt option 1 men's")
.col-xs-6
a(href="http://i.imgur.com/v9KlV4g.png" data-lightbox="img-enlarge")
img.img-responsive(src='http://i.imgur.com/v9KlV4g.png' alt="t-shirt option 2 men's")
.button-spacer
.row
.col-xs-6
a.button.btn.btn-block.btn-primary(href='/vote1') Vote for Design 1
.col-xs-6
a.button.btn.btn-block.btn-primary(href='/vote2') Vote for Design 2
.spacer
.row .row
.col-xs-12.col-sm-8.col-sm-offset-2 .col-xs-12.col-sm-8.col-sm-offset-2
h3 800 Hours of Practice: h3 800 Hours of Practice: