2013-12-20 13:48:33 -05:00
|
|
|
/**
|
|
|
|
* GET /
|
2014-01-07 18:15:14 -05:00
|
|
|
* Home page.
|
2013-12-20 13:48:33 -05:00
|
|
|
*/
|
2014-01-13 04:34:54 -05:00
|
|
|
|
2013-11-19 21:31:31 -05:00
|
|
|
exports.index = function(req, res) {
|
2014-11-06 12:46:24 -08:00
|
|
|
if (req.user) {
|
2014-12-23 08:48:28 -08:00
|
|
|
ch = req.user.challengesHash;
|
|
|
|
if (req.user.challengesHash[0] > 0) {
|
|
|
|
var max = Object.keys(ch).reduce(function(max, key) {
|
|
|
|
return (max === undefined || ch[key] > ch[max]) ? +key : max;
|
2014-11-06 12:46:24 -08:00
|
|
|
});
|
2014-12-23 08:48:28 -08:00
|
|
|
nextChallenge = max + 1;
|
|
|
|
res.redirect('challenges/' + nextChallenge);
|
|
|
|
} else {
|
|
|
|
res.redirect('challenges/0');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.render('home', {
|
2015-01-21 14:12:19 -08:00
|
|
|
title: 'Learn to Code and Become a Software Engineer',
|
|
|
|
landingPage: true
|
2014-12-23 08:48:28 -08:00
|
|
|
});
|
2014-11-06 12:46:24 -08:00
|
|
|
}
|
2014-12-23 08:48:28 -08:00
|
|
|
};
|