add tshirt voting mechanism

This commit is contained in:
Quincy Larson
2015-09-27 10:49:44 -07:00
parent 0634926af0
commit ccf5504537
3 changed files with 62 additions and 30 deletions

View File

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

View File

@ -76,6 +76,8 @@ module.exports = function(app) {
);
router.get('/account/unlink/:provider', getOauthUnlink);
router.get('/account', getAccount);
router.get('/vote1', vote1);
router.get('/vote2', vote1);
// Ensure this is the last route!
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

@ -18,35 +18,30 @@ block content
span.text-primary #{daysRunning}  
| days ago.
.spacer
if (user && !user.tshirtVote)
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.thumbnail
.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")
.caption
p.text-center Design 1 Women's
.col-xs-6.thumbnail
.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")
.caption
p.text-center Design 2 Women's
.button-spacer
.row
.col-xs-6.thumbnail
.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")
.caption
p.text-center Design 1 Men's
.col-xs-6.thumbnail
.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")
.caption
p.text-center Design 2 Men's
.button-spacer
.row
.col-xs-6
.button.btn.btn-block.btn-primary Vote for Design 1
a.button.btn.btn-block.btn-primary(href='/vote1') Vote for Design 1
.col-xs-6
.button.btn.btn-block.btn-primary Vote for Design 2
a.button.btn.btn-block.btn-primary(href='/vote2') Vote for Design 2
.spacer
.row
.col-xs-12.col-sm-8.col-sm-offset-2