This commit is contained in:
terakilobyte
2015-05-22 08:52:03 -04:00
12 changed files with 663 additions and 469 deletions

View File

@ -7,6 +7,10 @@
"mocha": true,
"node": true
},
"parser": "babel-eslint",
"plugins": [
"react"
],
"globals": {
"window": true,
"$": true,
@ -41,7 +45,7 @@
"valid-jsdoc": 2,
"valid-typeof": 2,
"block-scoped-var": 2,
"block-scoped-var": 0,
"complexity": 0,
"consistent-return": 2,
"curly": 2,
@ -215,6 +219,21 @@
"max-params": 0,
"max-statements": 0,
"no-bitwise": 1,
"no-plusplus": 0
"no-plusplus": 0,
"react/display-name": 1,
"react/jsx-boolean-value": 1,
"react/jsx-quotes": [1, "single", "avoid-escape"],
"react/jsx-no-undef": 1,
"react/jsx-sort-props": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1,
"react/no-did-mount-set-state": 2,
"react/no-did-update-set-state": 2,
"react/no-multi-comp": 2,
"react/prop-types": 2,
"react/react-in-jsx-scope": 1,
"react/self-closing-comp": 1,
"react/wrap-multilines": 1
}
}

View File

@ -1,27 +1,39 @@
/*eslint-disable no-unused-vars */
/**
* Created by nathanleniz on 5/15/15.
* Copyright (c) 2015, Free Code Camp
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var debug = require('debug')('freecc:cntr:challenges'),
var R = require('ramda'),
Challenge = require('./../models/Challenge'),
User = require('./../models/User'),
resources = require('./resources'),
R = require('ramda'),
moment = require('moment'),
MDNlinks = require('./../seed_data/bonfireMDNlinks');
var challengeMapWithNames = resources.getChallengeMapWithNames();
@ -31,9 +43,10 @@ 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
// for each key value, push the corresponding link
// from the MDNlinks object into a new array
if (links) {
links.forEach(function (value, index) {
links.forEach(function (value) {
populatedLinks.push(MDNlinks[value]);
});
}

View File

@ -1,7 +1,7 @@
var User = require('../models/User'),
resources = require('./resources'),
var R = require('ramda'),
debug = require('debug')('freecc:cntr:challengeMap'),
R = require('ramda');
User = require('../models/User'),
resources = require('./resources');
var challengeTypes = {
'HTML_CSS_JQ': 0,
@ -13,7 +13,7 @@ var challengeTypes = {
};
module.exports = {
challengeMap: function challengeMap(req, res) {
challengeMap: function challengeMap(req, res, next) {
var completedList = [];
if (req.user) {
@ -76,10 +76,10 @@ module.exports = {
});
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
var date1 = new Date("10/15/2014");
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));

View File

@ -0,0 +1,3 @@
{
"gitHubUserAgent": "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"
}

View File

@ -1,8 +1,6 @@
var _ = require('lodash'),
debug = require('debug')('freecc:cntr:fieldGuide'),
var R = require('ramda'),
FieldGuide = require('./../models/FieldGuide'),
resources = require('./resources'),
R = require('ramda');
resources = require('./resources');
exports.returnIndividualFieldGuide = function(req, res, next) {
var dashedName = req.params.fieldGuideName;
@ -12,30 +10,37 @@ exports.returnIndividualFieldGuide = function(req, res, next) {
if (req.user) {
var completed = req.user.completedFieldGuides;
var uncompletedFieldGuides = resources.allFieldGuideIds().filter(function (elem) {
var uncompletedFieldGuides = resources.allFieldGuideIds()
.filter(function (elem) {
if (completed.indexOf(elem) === -1) {
return elem;
}
});
req.user.uncompletedFieldGuides = uncompletedFieldGuides;
// TODO(berks): handle callback properly
req.user.save();
}
FieldGuide.find({'name': new RegExp(fieldGuideName, 'i')}, function(err, fieldGuideFromMongo) {
FieldGuide.find(
{ name: new RegExp(fieldGuideName, 'i') },
function(err, fieldGuideFromMongo) {
if (err) {
next(err);
return next(err);
}
if (fieldGuideFromMongo.length < 1) {
req.flash('errors', {
msg: "404: We couldn't find a field guide entry with that name. Please double check the name."
msg: "404: We couldn't find a field guide entry with that name. " +
'Please double check the name.'
});
return res.redirect('/field-guide');
}
var fieldGuide = R.head(fieldGuideFromMongo);
var dashedNameFull = fieldGuide.name.toLowerCase().replace(/\s/g, '-').replace(/\?/g, '');
var dashedNameFull =
fieldGuide.name.toLowerCase().replace(/\s/g, '-').replace(/\?/g, '');
if (dashedNameFull !== dashedName) {
return res.redirect('../field-guide/' + dashedNameFull);
}
@ -44,13 +49,15 @@ exports.returnIndividualFieldGuide = function(req, res, next) {
fieldGuideId: fieldGuide._id,
description: fieldGuide.description.join('')
});
});
}
);
};
exports.showAllFieldGuides = function(req, res) {
var data = {};
data.fieldGuideList = resources.allFieldGuideNames();
data.fieldGuideIds = resources.allFieldGuideIds();
if (req.user && req.user.completedFieldGuides) {
data.completedFieldGuides = req.user.completedFieldGuides;
} else {
@ -64,16 +71,22 @@ exports.returnNextFieldGuide = function(req, res, next) {
return res.redirect('/field-guide/how-do-i-use-this-guide?');
}
var displayedFieldGuides = FieldGuide.find({'_id': req.user.uncompletedFieldGuides[0]});
var displayedFieldGuides =
FieldGuide.find({'_id': req.user.uncompletedFieldGuides[0]});
displayedFieldGuides.exec(function(err, fieldGuide) {
if (err) {
return next(err);
}
if (err) { return next(err); }
fieldGuide = fieldGuide.pop();
if (typeof fieldGuide === 'undefined') {
if (req.user.completedFieldGuides.length > 0) {
req.flash('success', {
msg: "You've read all our current Field Guide entries. You can contribute to our Field Guide <a href='https://github.com/FreeCodeCamp/freecodecamp/blob/master/seed_data/field-guides.json'>here</a>."
msg: [
"You've read all our current Field Guide entries. You can ",
'contribute to our Field Guide ',
"<a href='https://github.com/FreeCodeCamp/freecodecamp/blob/",
"staging/seed_data/field-guides.json'>here</a>."
].join('')
});
}
return res.redirect('../field-guide/how-do-i-use-this-guide?');
@ -94,12 +107,10 @@ exports.completedFieldGuide = function (req, res, next) {
req.user.uncompletedFieldGuides.splice(index, 1);
}
req.user.save(function (err, user) {
req.user.save(function (err) {
if (err) {
return next(err);
}
if (user) {
res.send(true);
}
});
};

View File

@ -1,16 +1,16 @@
/**
* GET /
* Home page.
*/
var message =
'Learn to Code JavaScript and get a Coding Job by Helping Nonprofits';
exports.index = function(req, res, next) {
if (req.user && !req.user.profile.picture) {
req.user.profile.picture = 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
req.user.profile.picture =
'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
req.user.save(function(err) {
if (err) { return next(err); }
res.render('home', { title: message });
});
} else {
res.render('home', { title: message });
}
res.render('home', {
title: 'Learn to Code JavaScript and get a Coding Job by Helping Nonprofits'
});
};

View File

@ -1,16 +1,11 @@
var async = require('async'),
var moment = require('moment'),
Nonprofit = require('./../models/Nonprofit'),
resources = require('./resources'),
secrets = require('./../config/secrets'),
moment = require('moment'),
debug = require('debug')('freecc:cntr:nonprofits'),
R = require('ramda');
resources = require('./resources');
exports.nonprofitsDirectory = function(req, res) {
exports.nonprofitsDirectory = function(req, res, next) {
Nonprofit.find({estimatedHours: { $gt: 0 } }, function(err, nonprofits) {
if (err) {
next(err);
}
if (err) { return next(err); }
res.render('nonprofits/directory', {
title: 'Nonprofits we help',
nonprofits: nonprofits
@ -25,11 +20,16 @@ exports.areYouWithARegisteredNonprofit = function(req, res) {
});
};
exports.areTherePeopleThatAreAlreadyBenefitingFromYourServices = function(req, res) {
res.render('nonprofits/are-there-people-that-are-already-benefiting-from-your-services', {
exports.areTherePeopleThatAreAlreadyBenefitingFromYourServices =
function(req, res) {
res.render(
'nonprofits/' +
'are-there-people-that-are-already-benefiting-from-your-services',
{
title: 'Are there people already benefiting from your services',
step: 2
});
}
);
};
exports.okWithJavaScript = function(req, res) {
@ -83,11 +83,14 @@ exports.tellUsYourName = function(req, res) {
};
exports.yourNonprofitProjectApplicationHasBeenSubmitted = function(req, res) {
res.render('nonprofits/your-nonprofit-project-application-has-been-submitted', {
res.render(
'nonprofits/your-nonprofit-project-application-has-been-submitted',
{
title: 'Your Nonprofit Project application has been submitted!',
step: 10,
getBackDay: moment().weekday(5).format('dddd')
});
}
);
};
exports.otherSolutions = function(req, res) {
@ -98,17 +101,19 @@ exports.otherSolutions = function(req, res) {
exports.returnIndividualNonprofit = function(req, res, next) {
var dashedName = req.params.nonprofitName;
var nonprofitName = dashedName.replace(/\-/g, ' ');
Nonprofit.find({'name': new RegExp(nonprofitName, 'i')}, function(err, nonprofit) {
Nonprofit.find(
{ name: new RegExp(nonprofitName, 'i') },
function(err, nonprofit) {
if (err) {
next(err);
return next(err);
}
if (nonprofit.length < 1) {
req.flash('errors', {
msg: "404: We couldn't find a nonprofit with that name. Please double check the name."
msg: "404: We couldn't find a nonprofit with that name. " +
'Please double check the name.'
});
return res.redirect('/nonprofits');
@ -116,36 +121,52 @@ exports.returnIndividualNonprofit = function(req, res, next) {
nonprofit = nonprofit.pop();
var dashedNameFull = nonprofit.name.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
if (dashedNameFull !== dashedName) {
return res.redirect('../nonprofit/' + dashedNameFull);
}
var buttonActive = false;
if (req.user) {
if (req.user.uncompletedBonfires.length === 0) {
if (req.user.completedCoursewares.length > 63) {
var hasShownInterest = nonprofit.interestedCampers.filter(function ( obj ) {
var hasShownInterest =
nonprofit.interestedCampers.filter(function ( obj ) {
return obj.username === req.user.profile.username;
});
if (hasShownInterest.length === 0) {
buttonActive = true;
}
}
}
}
res.render('nonprofits/show', {
dashedName: dashedNameFull,
title: nonprofit.name,
logoUrl: nonprofit.logoUrl,
estimatedHours: nonprofit.estimatedHours,
projectDescription: nonprofit.projectDescription,
approvedOther: nonprofit.approvedDeliverables.indexOf('other') > -1,
approvedWebsite: nonprofit.approvedDeliverables.indexOf('website') > -1,
approvedDonor: nonprofit.approvedDeliverables.indexOf('donor') > -1,
approvedInventory: nonprofit.approvedDeliverables.indexOf('inventory') > -1,
approvedVolunteer: nonprofit.approvedDeliverables.indexOf('volunteer') > -1,
approvedForm: nonprofit.approvedDeliverables.indexOf('form') > -1,
approvedCommunity: nonprofit.approvedDeliverables.indexOf('community') > -1,
approvedELearning: nonprofit.approvedDeliverables.indexOf('eLearning') > -1,
approvedOther:
nonprofit.approvedDeliverables.indexOf('other') > -1,
approvedWebsite:
nonprofit.approvedDeliverables.indexOf('website') > -1,
approvedDonor:
nonprofit.approvedDeliverables.indexOf('donor') > -1,
approvedInventory:
nonprofit.approvedDeliverables.indexOf('inventory') > -1,
approvedVolunteer:
nonprofit.approvedDeliverables.indexOf('volunteer') > -1,
approvedForm:
nonprofit.approvedDeliverables.indexOf('form') > -1,
approvedCommunity:
nonprofit.approvedDeliverables.indexOf('community') > -1,
approvedELearning:
nonprofit.approvedDeliverables.indexOf('eLearning') > -1,
websiteLink: nonprofit.websiteLink,
imageUrl: nonprofit.imageUrl,
whatDoesNonprofitDo: nonprofit.whatDoesNonprofitDo,
@ -154,7 +175,8 @@ exports.returnIndividualNonprofit = function(req, res, next) {
buttonActive: buttonActive,
currentStatus: nonprofit.currentStatus
});
});
}
);
};
exports.showAllNonprofits = function(req, res) {
@ -163,19 +185,26 @@ exports.showAllNonprofits = function(req, res) {
res.send(data);
};
exports.interestedInNonprofit = function(req, res) {
exports.interestedInNonprofit = function(req, res, next) {
if (req.user) {
Nonprofit.findOne({name: new RegExp(req.params.nonprofitName.replace(/-/, ' '), 'i')}, function(err, nonprofit) {
Nonprofit.findOne(
{ name: new RegExp(req.params.nonprofitName.replace(/-/, ' '), 'i') },
function(err, nonprofit) {
if (err) { return next(err); }
nonprofit.interestedCampers.push({"username": req.user.profile.username,
"picture": req.user.profile.picture,
"timeOfInterest": Date.now()
nonprofit.interestedCampers.push({
username: req.user.profile.username,
picture: req.user.profile.picture,
timeOfInterest: Date.now()
});
nonprofit.save(function(err) {
if (err) { return done(err); }
req.flash('success', { msg: "Thanks for expressing interest in this nonprofit project! We've added you to this project as an interested camper!" });
if (err) { return next(err); }
req.flash('success', {
msg: 'Thanks for expressing interest in this nonprofit project! ' +
"We've added you to this project as an interested camper!"
});
res.redirect('back');
});
});
}
);
}
};

View File

@ -1,4 +1,15 @@
var async = require('async'),
path = require('path'),
moment = require('moment'),
Twit = require('twit'),
debug = require('debug')('freecc:cntr:resources'),
cheerio = require('cheerio'),
request = require('request'),
R = require('ramda'),
_ = require('lodash'),
fs = require('fs'),
constantStrings = require('./constantStrings.json'),
User = require('../models/User'),
Challenge = require('./../models/Challenge'),
Story = require('./../models/Story'),
@ -8,16 +19,7 @@ var async = require('async'),
resources = require('./resources.json'),
secrets = require('./../config/secrets'),
nonprofits = require('../seed_data/nonprofits.json'),
fieldGuides = require('../seed_data/field-guides.json'),
moment = require('moment'),
Twit = require('twit'),
https = require('https'),
debug = require('debug')('freecc:cntr:resources'),
cheerio = require('cheerio'),
request = require('request'),
R = require('ramda'),
_ = require('lodash'),
fs = require('fs');
fieldGuides = require('../seed_data/field-guides.json');
/**
* Cached values
@ -45,11 +47,14 @@ Array.zip = function(left, right, combinerFunction) {
(function() {
if (!challengeMap) {
var localChallengeMap = {};
var files = fs.readdirSync(__dirname + '/../seed_data/challenges');
var files = fs.readdirSync(
path.join(__dirname, '/../seed_data/challenges')
);
var keyCounter = 0;
files = files.map(function (file) {
return require(__dirname +
'/../seed_data/challenges/' + file);
return require(
path.join(__dirname, '/../seed_data/challenges/' + file)
);
});
files = files.sort(function (a, b) {
return a.order - b.order;
@ -208,13 +213,16 @@ module.exports = {
res.redirect('http://freecode.slack.com');
} else {
res.render('resources/chat', {
title: "Watch us code live on Twitch.tv"
title: 'Watch us code live on Twitch.tv'
});
}
},
catPhotoSubmit: function catPhotoSubmit(req, res) {
res.send('Success! You have submitted your cat photo. Return to your website by typing any letter into your code editor.')
res.send(
'Success! You have submitted your cat photo. Return to your website ' +
'by typing any letter into your code editor.'
);
},
nonprofits: function nonprofits(req, res) {
@ -247,7 +255,7 @@ module.exports = {
});
},
unsubscribe: function unsubscribe(req, res) {
unsubscribe: function unsubscribe(req, res, next) {
User.findOne({ email: req.params.email }, function(err, user) {
if (user) {
if (err) {
@ -268,52 +276,106 @@ module.exports = {
unsubscribed: function unsubscribed(req, res) {
res.render('resources/unsubscribed', {
title: "You have been 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) {
pulls = pulls ? Object.keys(JSON.parse(pulls)).length : "Can't connect to github";
request('https://api.github.com/repos/freecodecamp/freecodecamp/issues?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function (err, status2, issues) {
issues = ((pulls === parseInt(pulls)) && issues) ? Object.keys(JSON.parse(issues)).length - pulls : "Can't connect to GitHub";
res.send({"issues": issues, "pulls" : pulls});
});
githubCalls: function(req, res, next) {
var githubHeaders = {
headers: {
'User-Agent': constantStrings.gitHubUserAgent
},
port: 80
};
request(
[
'https://api.github.com/repos/freecodecamp/',
'freecodecamp/pulls?client_id=',
secrets.github.clientID,
'&client_secret=',
secrets.github.clientSecret
].join(''),
githubHeaders,
function(err, status1, pulls) {
if (err) { return next(err); }
pulls = pulls ?
Object.keys(JSON.parse(pulls)).length :
"Can't connect to github";
request(
[
'https://api.github.com/repos/freecodecamp/',
'freecodecamp/issues?client_id=',
secrets.github.clientID,
'&client_secret=',
secrets.github.clientSecret
].join(''),
githubHeaders,
function (err, status2, issues) {
if (err) { return next(err); }
issues = ((pulls === parseInt(pulls, 10)) && issues) ?
Object.keys(JSON.parse(issues)).length - pulls :
"Can't connect to GitHub";
res.send({
issues: issues,
pulls: pulls
});
}
);
}
);
},
trelloCalls: function(req, res, next) {
request('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(err, status, trello) {
request(
'https://trello.com/1/boards/BA3xVpz9/cards?key=' +
secrets.trello.key,
function(err, status, trello) {
if (err) { return next(err); }
trello = (status && status.statusCode === 200) ? (JSON.parse(trello)) : "Can't connect to to Trello";
trello = (status && status.statusCode === 200) ?
(JSON.parse(trello)) :
"Can't connect to to Trello";
res.end(JSON.stringify(trello));
});
},
bloggerCalls: function(req, res, next) {
request('https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets.blogger.key, function (err, status, blog) {
request(
'https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/' +
'posts?key=' +
secrets.blogger.key,
function (err, status, blog) {
if (err) { return next(err); }
blog = (status && status.statusCode === 200) ? JSON.parse(blog) : "Can't connect to Blogger";
blog = (status && status.statusCode === 200) ?
JSON.parse(blog) :
"Can't connect to Blogger";
res.end(JSON.stringify(blog));
});
}
);
},
about: function(req, res, next) {
if (req.user) {
if (!req.user.profile.picture || req.user.profile.picture === "https://s3.amazonaws.com/freecodecamp/favicons/apple-touch-icon-180x180.png") {
req.user.profile.picture = "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png";
if (
!req.user.profile.picture ||
req.user.profile.picture.indexOf('apple-touch-icon-180x180.png') !== -1
) {
req.user.profile.picture =
'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
// TODO(berks): unhandled callback
req.user.save();
}
}
var date1 = new Date("10/15/2014");
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));
var announcements = resources.announcements;
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
User.count({}, function (err, c3) {
if (err) {
@ -331,26 +393,28 @@ module.exports = {
},
randomPhrase: function() {
return resources.phrases[Math.floor(
Math.random() * resources.phrases.length)];
return resources.phrases[
Math.floor(Math.random() * resources.phrases.length)
];
},
randomVerb: function() {
return resources.verbs[Math.floor(
Math.random() * resources.verbs.length)];
return resources.verbs[
Math.floor(Math.random() * resources.verbs.length)
];
},
randomCompliment: function() {
return resources.compliments[Math.floor(
Math.random() * resources.compliments.length)];
return resources.compliments[
Math.floor(Math.random() * resources.compliments.length)
];
},
allFieldGuideIds: function() {
if (allFieldGuideIds) {
return allFieldGuideIds;
} else {
allFieldGuideIds = fieldGuides.
map(function (elem) {
allFieldGuideIds = fieldGuides.map(function (elem) {
return elem._id;
});
return allFieldGuideIds;
@ -361,11 +425,8 @@ module.exports = {
if (allFieldGuideNames) {
return allFieldGuideNames;
} else {
allFieldGuideNames = fieldGuides.
map(function (elem) {
return {
name: elem.name
};
allFieldGuideNames = fieldGuides.map(function (elem) {
return { name: elem.name };
});
return allFieldGuideNames;
}
@ -375,11 +436,8 @@ module.exports = {
if (allNonprofitNames) {
return allNonprofitNames;
} else {
allNonprofitNames = nonprofits.
map(function (elem) {
return {
name: elem.name
};
allNonprofitNames = nonprofits.map(function (elem) {
return { name: elem.name };
});
return allNonprofitNames;
}
@ -397,15 +455,24 @@ module.exports = {
var $ = cheerio.load(body);
var metaDescription = $("meta[name='description']");
var metaImage = $("meta[property='og:image']");
var urlImage = metaImage.attr('content') ? metaImage.attr('content') : '';
var urlImage = metaImage.attr('content') ?
metaImage.attr('content') :
'';
var metaTitle = $('title');
var description = metaDescription.attr('content') ? metaDescription.attr('content') : '';
result.title = metaTitle.text().length < 90 ? metaTitle.text() : metaTitle.text().slice(0, 87) + "...";
var description = metaDescription.attr('content') ?
metaDescription.attr('content') :
'';
result.title = metaTitle.text().length < 90 ?
metaTitle.text() :
metaTitle.text().slice(0, 87) + '...';
result.image = urlImage;
result.description = description;
callback(null, result);
} else {
callback('failed');
callback(new Error('failed'));
}
});
})();
@ -465,24 +532,33 @@ module.exports = {
}
},
codepenResources: {
twitter: function(req, res) {
twitter: function(req, res, next) {
// sends out random tweets about javascript
var T = new Twit({
consumer_key: secrets.twitter.consumerKey,
consumer_secret: secrets.twitter.consumerSecret,
access_token: secrets.twitter.token,
access_token_secret: secrets.twitter.tokenSecret
'consumer_key': secrets.twitter.consumerKey,
'consumer_secret': secrets.twitter.consumerSecret,
'access_token': secrets.twitter.token,
'access_token_secret': secrets.twitter.tokenSecret
});
var screenName;
if (req.params.screenName) {
screenName = req.params.screenName;
} else {
screenName = 'freecodecamp';
}
T.get('statuses/user_timeline', {screen_name: screenName, count:10}, function(err, data, response) {
T.get(
'statuses/user_timeline',
{
'screen_name': screenName,
count: 10
},
function(err, data) {
if (err) { return next(err); }
return res.json(data);
});
}
);
},
twitterFCCStream: function() {
// sends out a tweet stream from FCC's account

View File

@ -129,7 +129,7 @@ exports.returnIndividualStory = function(req, res, next) {
if (story.length < 1) {
req.flash('errors', {
msg: "404: We couldn't find a story with that name. " +
"Please double check the name."
'Please double check the name.'
});
return res.redirect('/news/');
@ -149,7 +149,7 @@ exports.returnIndividualStory = function(req, res, next) {
if (votedObj.length > 0) {
userVoted = true;
}
} catch(err) {
} catch(e) {
userVoted = false;
}
res.render('stories/index', {

View File

@ -53,6 +53,9 @@ exports.postSignin = function(req, res, next) {
return next(err);
}
req.flash('success', { msg: 'Success! You are logged in.' });
if (/hotStories/.test(req.session.returnTo)) {
return res.redirect('../news');
}
return res.redirect(req.session.returnTo || '/');
});
})(req, res, next);
@ -102,8 +105,6 @@ exports.getEmailSignup = function(req, res) {
*/
exports.postEmailSignup = function(req, res, next) {
req.assert('email', 'valid email required').isEmail();
var errors = req.validationErrors();
@ -134,7 +135,8 @@ exports.postEmailSignup = function(req, res, next) {
password: req.body.password,
profile: {
username: req.body.username.trim(),
picture: 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png'
picture:
'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png'
}
});
@ -149,7 +151,9 @@ exports.postEmailSignup = function(req, res, next) {
});
return res.redirect('/email-signup');
}
User.findOne({'profile.username': req.body.username }, function(err, existingUsername) {
User.findOne(
{ 'profile.username': req.body.username },
function(err, existingUsername) {
if (err) {
return next(err);
}
@ -181,8 +185,10 @@ exports.postEmailSignup = function(req, res, next) {
text: [
'Greetings from San Francisco!\n\n',
'Thank you for joining our community.\n',
'Feel free to email us at this address if you have any questions about Free Code Camp.\n',
'And if you have a moment, check out our blog: blog.freecodecamp.com.\n',
'Feel free to email us at this address if you have ',
'any questions about Free Code Camp.\n',
'And if you have a moment, check out our blog: ',
'blog.freecodecamp.com.\n',
'Good luck with the challenges!\n\n',
'- the Volunteer Camp Counselor Team'
].join('')
@ -220,9 +226,11 @@ exports.getAccountAngular = function(req, res) {
*/
exports.checkUniqueUsername = function(req, res, next) {
User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) {
User.count(
{ 'profile.username': req.params.username.toLowerCase() },
function (err, data) {
if (err) { return next(err); }
if (data == 1) {
if (data === 1) {
return res.send(true);
} else {
return res.send(false);
@ -234,14 +242,17 @@ exports.checkUniqueUsername = function(req, res, next) {
* Existing username check
*/
exports.checkExistingUsername = function(req, res, next) {
User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) {
User.count(
{ 'profile.username': req.params.username.toLowerCase() },
function (err, data) {
if (err) { return next(err); }
if (data === 1) {
return res.send(true);
} else {
return res.send(false);
}
});
}
);
};
/**
@ -249,14 +260,17 @@ exports.checkExistingUsername = function(req, res, next) {
*/
exports.checkUniqueEmail = function(req, res, next) {
User.count({'email': decodeURIComponent(req.params.email).toLowerCase()}, function (err, data) {
User.count(
{ email: decodeURIComponent(req.params.email).toLowerCase() },
function (err, data) {
if (err) { return next(err); }
if (data === 1) {
return res.send(true);
} else {
return res.send(false);
}
});
}
);
};
@ -266,8 +280,13 @@ exports.checkUniqueEmail = function(req, res, next) {
*/
exports.returnUser = function(req, res, next) {
User.find({'profile.username': req.params.username.toLowerCase()}, function(err, user) {
if (err) { debug('Username err: ', err); next(err); }
User.find(
{ 'profile.username': req.params.username.toLowerCase() },
function(err, user) {
if (err) {
debug('Username err: ', err);
return next(err);
}
if (user[0]) {
user = user[0];
@ -302,14 +321,21 @@ exports.returnUser = function(req, res, next) {
user.currentStreak = 1;
var today = moment(Date.now()).format('YYYY-MM-DD');
if (moment(today).toString() === moment(timeKeys[0]).toString() ||
if (
moment(today).toString() === moment(timeKeys[0]).toString() ||
moment(today).subtract(1, 'd').toString() ===
moment(timeKeys[0]).toString()) {
for (var i = 1; i <= timeKeys.length; i++) {
if (moment(timeKeys[i - 1]).subtract(1, 'd').toString()
=== moment(timeKeys[i]).toString()) {
debug(timeKeys[i - 1], timeKeys[i]);
moment(timeKeys[0]).toString()
) {
for (var _i = 1; _i <= timeKeys.length; _i++) {
if (
moment(timeKeys[_i - 1]).subtract(1, 'd').toString() ===
moment(timeKeys[_i]).toString()
) {
debug(timeKeys[_i - 1], timeKeys[_i]);
tmpLongest++;
if (tmpLongest > user.currentStreak) {
user.currentStreak = tmpLongest;
}
@ -325,7 +351,6 @@ exports.returnUser = function(req, res, next) {
if (err) {
return next(err);
}
});
var data = {};
var progressTimestamps = user.progressTimestamps;
@ -338,6 +363,7 @@ exports.returnUser = function(req, res, next) {
var challenges = user.completedCoursewares.filter(function ( obj ) {
return !!obj.solution;
});
res.render('account/show', {
title: 'Camper ' + user.profile.username + '\'s portfolio',
username: user.profile.username,
@ -366,17 +392,21 @@ exports.returnUser = function(req, res, next) {
}),
calender: data,
moment: moment,
longestStreak: user.longestStreak + (user.longestStreak === 1 ? " day" : " days"),
currentStreak: user.currentStreak + (user.currentStreak === 1 ? " day" : " days")
longestStreak: user.longestStreak +
(user.longestStreak === 1 ? ' day' : ' days'),
currentStreak: user.currentStreak +
(user.currentStreak === 1 ? ' day' : ' days')
});
});
} else {
req.flash('errors', {
msg: "404: We couldn't find a page with that url. Please double check the link."
msg: "404: We couldn't find a page with that url. " +
'Please double check the link.'
});
return res.redirect('/');
}
});
}
);
};
@ -385,9 +415,9 @@ exports.returnUser = function(req, res, next) {
* Update profile information.
*/
exports.updateProgress = function(req, res) {
exports.updateProgress = function(req, res, next) {
User.findById(req.user.id, function(err, user) {
if (err) return next(err);
if (err) { return next(err); }
user.email = req.body.email || '';
user.profile.name = req.body.name || '';
user.profile.gender = req.body.gender || '';
@ -395,7 +425,7 @@ exports.updateProgress = function(req, res) {
user.profile.website = req.body.website || '';
user.save(function(err) {
if (err) return next(err);
if (err) { return next(err); }
req.flash('success', { msg: 'Profile information updated.' });
res.redirect('/account');
});
@ -409,8 +439,8 @@ exports.updateProgress = function(req, res) {
exports.postUpdateProfile = function(req, res, next) {
User.findById(req.user.id, function(err, user) {
if (err) return next(err);
User.findById(req.user.id, function(err) {
if (err) { return next(err); }
var errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
@ -422,18 +452,23 @@ exports.postUpdateProfile = function(req, res, next) {
return next(err);
}
var user = req.user;
if (existingEmail && existingEmail.email != user.email) {
if (existingEmail && existingEmail.email !== user.email) {
req.flash('errors', {
msg: "An account with that email address already exists."
msg: 'An account with that email address already exists.'
});
return res.redirect('/account');
}
User.findOne({ 'profile.username': req.body.username }, function(err, existingUsername) {
User.findOne(
{ 'profile.username': req.body.username },
function(err, existingUsername) {
if (err) {
return next(err);
}
var user = req.user;
if (existingUsername && existingUsername.profile.username !== user.profile.username) {
if (
existingUsername &&
existingUsername.profile.username !== user.profile.username
) {
req.flash('errors', {
msg: 'An account with that username already exists.'
});
@ -449,7 +484,10 @@ exports.postUpdateProfile = function(req, res, next) {
user.profile.codepenProfile = req.body.codepenProfile.trim() || '';
user.profile.twitterHandle = req.body.twitterHandle.trim() || '';
user.profile.bio = req.body.bio.trim() || '';
user.profile.picture = req.body.picture.trim() || 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
user.profile.picture = req.body.picture.trim() ||
'https://s3.amazonaws.com/freecodecamp/' +
'camper-image-placeholder.png';
user.portfolio.website1Title = req.body.website1Title.trim() || '';
user.portfolio.website1Link = req.body.website1Link.trim() || '';
user.portfolio.website1Image = req.body.website1Image.trim() || '';
@ -478,7 +516,8 @@ exports.postUpdateProfile = function(req, res, next) {
}
);
});
});
}
);
});
});
};
@ -538,7 +577,7 @@ exports.getOauthUnlink = function(req, res, next) {
User.findById(req.user.id, function(err, user) {
if (err) { return next(err); }
user[provider] = undefined;
user[provider] = null;
user.tokens =
_.reject(user.tokens, function(token) {
return token.kind === provider;
@ -557,7 +596,7 @@ exports.getOauthUnlink = function(req, res, next) {
* Reset Password page.
*/
exports.getReset = function(req, res) {
exports.getReset = function(req, res, next) {
if (req.isAuthenticated()) {
return res.redirect('/');
}
@ -607,8 +646,8 @@ exports.postReset = function(req, res, next) {
}
user.password = req.body.password;
user.resetPasswordToken = undefined;
user.resetPasswordExpires = undefined;
user.resetPasswordToken = null;
user.resetPasswordExpires = null;
user.save(function(err) {
if (err) { return done(err); }

View File

@ -11,6 +11,7 @@
},
"scripts": {
"start": "node app.js",
"lint": "eslint --ext=.js,.jsx .",
"test": "mocha"
},
"license": "BSD-3-Clause",
@ -82,10 +83,13 @@
"yui": "~3.18.1"
},
"devDependencies": {
"babel-eslint": "^3.1.7",
"blessed": "~0.0.37",
"bower-main-files": "~0.0.4",
"browser-sync": "~1.8.1",
"chai": "~1.10.0",
"eslint": "^0.21.2",
"eslint-plugin-react": "^2.3.0",
"gulp": "~3.8.8",
"gulp-eslint": "~0.9.0",
"gulp-inject": "~1.0.2",

View File

@ -94,7 +94,7 @@
"Click \"News\" in the upper right hand corner.",
"You'll see a variety of links that have been submitted. Click on the \"Discuss\" button under one of them.",
"You can upvote links. This will push the link up the rankings of hot links.",
"You an also comment on a link. If someone responds to your comment, you'll get an email notification so you can come back and respond to them.",
"You can also comment on a link. If someone responds to your comment, you'll get an email notification so you can come back and respond to them.",
"You can also submit links. You can modify the link's headline and also leave an initial comment about the link.",
"You can view the portfolio pages of any camper who has posted links or comments on Camper News. Just click on their photo.",
"When you submit a link, you'll get a point. You will also get a point each time someone upvotes your link.",