Merge branch 'staging' of github.com:FreeCodeCamp/freecodecamp into staging
This commit is contained in:
@@ -32,50 +32,30 @@
|
||||
|
||||
var R = require('ramda'),
|
||||
utils = require('../utils'),
|
||||
userMigration = require('../utils/middleware').userMigration,
|
||||
MDNlinks = require('../../seed/bonfireMDNlinks');
|
||||
userMigration = require('../utils/middleware').userMigration;
|
||||
|
||||
var challengeMapWithNames = utils.getChallengeMapWithNames();
|
||||
var challengeMapWithIds = utils.getChallengeMapWithIds();
|
||||
var challengeMapWithDashedNames = utils.getChallengeMapWithDashedNames();
|
||||
|
||||
|
||||
function getMDNlinks(links) {
|
||||
// takes in an array of links, which are strings
|
||||
var populatedLinks = [];
|
||||
|
||||
// for each key value, push the corresponding link
|
||||
// from the MDNlinks object into a new array
|
||||
if (links) {
|
||||
links.forEach(function (value) {
|
||||
populatedLinks.push(MDNlinks[value]);
|
||||
});
|
||||
}
|
||||
return populatedLinks;
|
||||
}
|
||||
var getMDNLinks = utils.getMDNLinks;
|
||||
|
||||
module.exports = function(app) {
|
||||
var router = app.loopback.Router();
|
||||
var Challenge = app.models.Challenge;
|
||||
var User = app.models.User;
|
||||
|
||||
router.get(
|
||||
'/challenges/next-challenge',
|
||||
userMigration,
|
||||
returnNextChallenge
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/challenges/:challengeName',
|
||||
userMigration,
|
||||
returnIndividualChallenge
|
||||
);
|
||||
|
||||
router.get('/challenges/', userMigration, returnCurrentChallenge);
|
||||
router.post('/completed-challenge/', completedChallenge);
|
||||
router.post('/completed-zipline-or-basejump', completedZiplineOrBasejump);
|
||||
router.post('/completed-bonfire', completedBonfire);
|
||||
|
||||
// the follow routes are covered by userMigration
|
||||
router.use(userMigration);
|
||||
router.get('/challenges/next-challenge', returnNextChallenge);
|
||||
router.get('/challenges/:challengeName', returnIndividualChallenge);
|
||||
router.get('/challenges/', returnCurrentChallenge);
|
||||
router.get('/map', challengeMap);
|
||||
|
||||
app.use(router);
|
||||
|
||||
function returnNextChallenge(req, res, next) {
|
||||
@@ -295,7 +275,7 @@ module.exports = function(app) {
|
||||
bonfires: challenge,
|
||||
challengeId: challenge.id,
|
||||
MDNkeys: challenge.MDNlinks,
|
||||
MDNlinks: getMDNlinks(challenge.MDNlinks),
|
||||
MDNlinks: getMDNLinks(challenge.MDNlinks),
|
||||
challengeType: challenge.challengeType
|
||||
});
|
||||
}
|
||||
@@ -547,4 +527,51 @@ module.exports = function(app) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function challengeMap(req, res, next) {
|
||||
var completedList = [];
|
||||
|
||||
if (req.user) {
|
||||
completedList = req.user.completedChallenges;
|
||||
}
|
||||
|
||||
var noDuplicatedChallenges = R.uniq(completedList);
|
||||
|
||||
var completedChallengeList = noDuplicatedChallenges
|
||||
.map(function(challenge) {
|
||||
// backwards compatibility
|
||||
return (challenge.id || challenge._id);
|
||||
});
|
||||
var challengeList = utils.
|
||||
getChallengeMapForDisplay(completedChallengeList);
|
||||
|
||||
Object.keys(challengeList).forEach(function(key) {
|
||||
challengeList[key].completed = challengeList[key]
|
||||
.challenges.filter(function(elem) {
|
||||
// backwards compatibility hack
|
||||
return completedChallengeList.indexOf(elem.id || elem._id) > -1;
|
||||
});
|
||||
});
|
||||
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
var date1 = new Date('10/15/2014');
|
||||
var date2 = new Date();
|
||||
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
||||
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||
|
||||
User.count(function(err, camperCount) {
|
||||
if (err) { return next(err); }
|
||||
|
||||
res.render('challengeMap/show', {
|
||||
daysRunning: daysRunning,
|
||||
camperCount: numberWithCommas(camperCount),
|
||||
title: "A map of all Free Code Camp's Challenges",
|
||||
challengeList: challengeList,
|
||||
completedChallengeList: completedChallengeList
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@@ -1,66 +0,0 @@
|
||||
var R = require('ramda'),
|
||||
// debug = require('debug')('freecc:cntr:challengeMap'),
|
||||
utils = require('./../utils'),
|
||||
middleware = require('../utils/middleware');
|
||||
|
||||
|
||||
module.exports = function(app) {
|
||||
var User = app.models.User;
|
||||
var router = app.loopback.Router();
|
||||
|
||||
router.get('/map', middleware.userMigration, challengeMap);
|
||||
router.get('/learn-to-code', function(req, res) {
|
||||
res.redirect(301, '/map');
|
||||
});
|
||||
router.get('/about', function(req, res) {
|
||||
res.redirect(301, '/map');
|
||||
});
|
||||
|
||||
app.use(router);
|
||||
|
||||
function challengeMap(req, res, next) {
|
||||
var completedList = [];
|
||||
|
||||
if (req.user) {
|
||||
completedList = req.user.completedChallenges;
|
||||
}
|
||||
|
||||
var noDuplicatedChallenges = R.uniq(completedList);
|
||||
|
||||
var completedChallengeList = noDuplicatedChallenges
|
||||
.map(function(challenge) {
|
||||
return (challenge.id || challenge._id); // backwards compatibility
|
||||
});
|
||||
var challengeList = utils.
|
||||
getChallengeMapForDisplay(completedChallengeList);
|
||||
|
||||
Object.keys(challengeList).forEach(function(key) {
|
||||
challengeList[key].completed = challengeList[key]
|
||||
.challenges.filter(function(elem) {
|
||||
return completedChallengeList.indexOf(elem.id || elem._id) > -1;
|
||||
//backwards compatibility hack
|
||||
});
|
||||
});
|
||||
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
var date1 = new Date('10/15/2014');
|
||||
var date2 = new Date();
|
||||
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
||||
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||
|
||||
User.count(function(err, camperCount) {
|
||||
if (err) { return next(err); }
|
||||
|
||||
res.render('challengeMap/show', {
|
||||
daysRunning: daysRunning,
|
||||
camperCount: numberWithCommas(camperCount),
|
||||
title: "A map of all Free Code Camp's Challenges",
|
||||
challengeList: challengeList,
|
||||
completedChallengeList: completedChallengeList
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
@@ -18,5 +18,13 @@ module.exports = function(app) {
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/learn-to-code', function(req, res) {
|
||||
res.redirect(301, '/map');
|
||||
});
|
||||
|
||||
router.get('/about', function(req, res) {
|
||||
res.redirect(301, '/map');
|
||||
});
|
||||
|
||||
app.use(router);
|
||||
};
|
||||
|
@@ -3,6 +3,7 @@ var secrets = require('../config/secrets');
|
||||
module.exports = {
|
||||
db: {
|
||||
connector: 'mongodb',
|
||||
connectionTimeout: 15000,
|
||||
url: process.env.MONGOHQ_URL
|
||||
},
|
||||
mail: {
|
||||
|
@@ -41,7 +41,7 @@ module.exports = {
|
||||
},
|
||||
'google-login': {
|
||||
provider: 'google',
|
||||
authScheme: 'oauth2',
|
||||
authScheme: 'oauth',
|
||||
module: 'passport-google-oauth2',
|
||||
clientID: process.env.GOOGLE_ID,
|
||||
clientSecret: process.env.GOOGLE_SECRET,
|
||||
@@ -55,7 +55,7 @@ module.exports = {
|
||||
},
|
||||
'google-link': {
|
||||
provider: 'google',
|
||||
authScheme: 'oauth2',
|
||||
authScheme: 'oauth',
|
||||
module: 'passport-google-oauth2',
|
||||
clientID: process.env.GOOGLE_ID,
|
||||
clientSecret: process.env.GOOGLE_SECRET,
|
||||
|
@@ -1,5 +1,6 @@
|
||||
require('dotenv').load();
|
||||
require('pmx').init();
|
||||
var pmx = require('pmx');
|
||||
pmx.init();
|
||||
// handle uncaught exceptions. Forever will restart process on shutdown
|
||||
|
||||
var R = require('ramda'),
|
||||
@@ -20,7 +21,6 @@ var R = require('ramda'),
|
||||
path = require('path'),
|
||||
expressValidator = require('express-validator'),
|
||||
lessMiddleware = require('less-middleware'),
|
||||
pmx = require('pmx'),
|
||||
|
||||
passportProviders = require('./passport-providers'),
|
||||
/**
|
||||
@@ -42,12 +42,6 @@ app.set('port', process.env.PORT || 3000);
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'jade');
|
||||
|
||||
//if (process.env.NODE_ENV === 'production') {
|
||||
// app.use(forceDomain({
|
||||
// hostname: 'www.freecodecamp.com'
|
||||
// }));
|
||||
//}
|
||||
|
||||
app.use(compress());
|
||||
app.use(lessMiddleware(path.join(__dirname, '/public')));
|
||||
app.use(logger('dev'));
|
||||
@@ -98,6 +92,8 @@ var trusted = [
|
||||
'https://freecodecamp.com',
|
||||
'https://freecodecamp.org',
|
||||
'*.freecodecamp.org',
|
||||
// NOTE(berks): add the following as the blob above was not covering www
|
||||
'http://www.freecodecamp.org',
|
||||
'ws://freecodecamp.com/',
|
||||
'ws://www.freecodecamp.com/',
|
||||
'*.gstatic.com',
|
||||
@@ -143,7 +139,8 @@ app.use(helmet.csp({
|
||||
'*.aspnetcdn.com',
|
||||
'*.d3js.org',
|
||||
'https://cdn.inspectlet.com/inspectlet.js',
|
||||
'http://cdn.inspectlet.com/inspectlet.js'
|
||||
'http://cdn.inspectlet.com/inspectlet.js',
|
||||
'http://www.freecodecamp.org'
|
||||
].concat(trusted),
|
||||
'connect-src': [].concat(trusted),
|
||||
styleSrc: [
|
||||
@@ -259,6 +256,8 @@ R.keys(passportProviders).map(function(strategy) {
|
||||
|
||||
// if (process.env.NODE_ENV === 'development') {
|
||||
if (true) { // eslint-disable-line
|
||||
// NOTE(berks): adding pmx here for Beta test. Remove for production
|
||||
app.use(pmx.expressErrorHandler());
|
||||
app.use(errorHandler({
|
||||
log: true
|
||||
}));
|
||||
|
@@ -7,6 +7,7 @@ var path = require('path'),
|
||||
fs = require('fs'),
|
||||
|
||||
|
||||
MDNlinks = require('../../seed/bonfireMDNlinks'),
|
||||
resources = require('./resources.json'),
|
||||
nonprofits = require('../../seed/nonprofits.json'),
|
||||
fieldGuides = require('../../seed/field-guides.json');
|
||||
@@ -16,7 +17,7 @@ var path = require('path'),
|
||||
*/
|
||||
var allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
|
||||
challengeMap, challengeMapForDisplay, challengeMapWithIds,
|
||||
challengeMapWithNames, allChallengeIds, allChallenges,
|
||||
challengeMapWithNames, allChallengeIds,
|
||||
challengeMapWithDashedNames;
|
||||
|
||||
/**
|
||||
@@ -216,5 +217,18 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
})();
|
||||
},
|
||||
|
||||
getMDNLinks: function(links) {
|
||||
if (!links) {
|
||||
return [];
|
||||
}
|
||||
// takes in an array of links, which are strings
|
||||
|
||||
// for each key value, push the corresponding link
|
||||
// from the MDNlinks object into a new array
|
||||
return links.map(function(value) {
|
||||
return MDNlinks[value];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user