Merge branch 'staging' of github.com:FreeCodeCamp/freecodecamp into staging

This commit is contained in:
Quincy Larson
2015-08-18 23:48:02 -07:00
11 changed files with 57 additions and 16 deletions

View File

@ -47,7 +47,7 @@ export default function({ models }) {
modified modified
}); });
} }
if (identity.userId !== userId) { if (identity.userId.toString() !== userId.toString()) {
return Observable.throw( return Observable.throw(
new Error('An account is already linked to that profile') new Error('An account is already linked to that profile')
); );

View File

@ -137,7 +137,9 @@ module.exports = function(app) {
// unless the next block is undefined, which means no next block // unless the next block is undefined, which means no next block
let nextChallengeName = firstChallenge; let nextChallengeName = firstChallenge;
const challengeId = req.user.currentChallenge.challengeId; const challengeId = req.user.currentChallenge ?
req.user.currentChallenge.challengeId :
'bd7123c8c441eddfaeb5bdef';
// find challenge // find challenge
return challenge$ return challenge$
.map(challenge => challenge.toJSON()) .map(challenge => challenge.toJSON())
@ -320,7 +322,7 @@ module.exports = function(app) {
var challengeData = { var challengeData = {
id: challengeId, id: challengeId,
name: req.body.challengeInfo.challengeName, name: req.body.challengeInfo.challengeName || '',
completedDate: Math.round(+new Date()), completedDate: Math.round(+new Date()),
solution: req.body.challengeInfo.solution, solution: req.body.challengeInfo.solution,
challengeType: 5 challengeType: 5
@ -399,7 +401,7 @@ module.exports = function(app) {
{ {
id: id || challengeId, id: id || challengeId,
completedDate: completedDate, completedDate: completedDate,
name: name || challengeName, name: name || challengeName || '',
solution: null, solution: null,
githubLink: null, githubLink: null,
verified: true verified: true
@ -446,7 +448,7 @@ module.exports = function(app) {
var challengeData = { var challengeData = {
id: challengeId, id: challengeId,
name: req.body.challengeInfo.challengeName, name: req.body.challengeInfo.challengeName || '',
completedDate: completedDate, completedDate: completedDate,
solution: solutionLink, solution: solutionLink,
githubLink: githubLink, githubLink: githubLink,

View File

@ -18,6 +18,7 @@ var time48Hours = 172800000;
var unDasherize = utils.unDasherize; var unDasherize = utils.unDasherize;
var dasherize = utils.dasherize; var dasherize = utils.dasherize;
var getURLTitle = utils.getURLTitle; var getURLTitle = utils.getURLTitle;
var ifNoUser401 = require('../utils/middleware').ifNoUser401;
function hotRank(timeValue, rank) { function hotRank(timeValue, rank) {
/* /*
@ -63,12 +64,12 @@ module.exports = function(app) {
router.get('/stories/hotStories', hotJSON); router.get('/stories/hotStories', hotJSON);
router.get('/stories/submit', submitNew); router.get('/stories/submit', submitNew);
router.get('/stories/submit/new-story', preSubmit); router.get('/stories/submit/new-story', preSubmit);
router.post('/stories/preliminary', newStory); router.post('/stories/preliminary', ifNoUser401, newStory);
router.post('/stories/', storySubmission); router.post('/stories/', ifNoUser401, storySubmission);
router.get('/news/', hot); router.get('/news/', hot);
router.post('/stories/search', getStories); router.post('/stories/search', getStories);
router.get('/news/:storyName', returnIndividualStory); router.get('/news/:storyName', returnIndividualStory);
router.post('/stories/upvote/', upvote); router.post('/stories/upvote/', ifNoUser401, upvote);
router.get('/stories/:storyName', redirectToNews); router.get('/stories/:storyName', redirectToNews);
app.use(router); app.use(router);
@ -107,8 +108,12 @@ module.exports = function(app) {
}); });
} }
function preSubmit(req, res) { function preSubmit(req, res, next) {
var data = req.query; var data = req.query;
if (typeof data.url !== 'string') {
req.flash('errors', { msg: 'No URL supplied with story' });
return next(new TypeError('No URL supplied with story'));
}
var cleanedData = cleanData(data.url); var cleanedData = cleanData(data.url);
if (data.url.replace(/&/g, '&') !== cleanedData) { if (data.url.replace(/&/g, '&') !== cleanedData) {

View File

@ -156,7 +156,7 @@ module.exports = function(app) {
}); });
const bonfires = user.completedChallenges.filter(function(obj) { const bonfires = user.completedChallenges.filter(function(obj) {
return obj.challengeType === 5 && obj.name.match(/Bonfire/g); return obj.challengeType === 5 && (obj.name || '').match(/Bonfire/g);
}); });
res.render('account/show', { res.render('account/show', {

View File

@ -3,7 +3,7 @@ var secrets = require('../config/secrets');
module.exports = { module.exports = {
db: { db: {
connector: 'mongodb', connector: 'mongodb',
connectionTimeout: 5000, connectionTimeout: 10000,
url: secrets.db url: secrets.db
}, },
mail: { mail: {

View File

@ -1,10 +1,31 @@
const pathsOfNoReturn = [
'link',
'bower_components',
'auth',
'login',
'logout',
'signin',
'signup',
'fonts',
'favicon',
'js',
'css'
];
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
export default function addReturnToUrl() { export default function addReturnToUrl() {
return function(req, res, next) { return function(req, res, next) {
// Remember original destination before login. // Remember original destination before login.
var path = req.path.split('/')[1]; var path = req.path.split('/')[1];
if (/auth|login|logout|signin|signup|fonts|favicon/i.test(path)) {
if (req.method !== 'GET') {
return next(); return next();
} else if (/\/stories\/\w+/i.test(req.path)) { }
if (pathsOfNoReturnRegex.test(path)) {
return next();
}
if (/\/stories\/\w+/i.test(req.path)) {
return next(); return next();
} }
req.session.returnTo = req.path; req.session.returnTo = req.path;

View File

@ -12,12 +12,12 @@ exports.userMigration = function userMigration(req, res, next) {
if (!req.user || req.user.completedChallenges.length !== 0) { if (!req.user || req.user.completedChallenges.length !== 0) {
return next(); return next();
} }
req.user.completedChallenges = R.filter(function (elem) { req.user.completedChallenges = R.filter(function(elem) {
// getting rid of undefined // getting rid of undefined
return elem; return elem;
}, R.concat( }, R.concat(
req.user.completedCoursewares, req.user.completedCoursewares,
req.user.completedBonfires.map(function (bonfire) { req.user.completedBonfires.map(function(bonfire) {
return ({ return ({
completedDate: bonfire.completedDate, completedDate: bonfire.completedDate,
id: bonfire.id, id: bonfire.id,
@ -51,3 +51,10 @@ exports.ifNoUserSend = function ifNoUserSend(sendThis) {
return res.status(200).send(sendThis); return res.status(200).send(sendThis);
}; };
}; };
exports.ifNoUser401 = function ifNoUser401(req, res, next) {
if (req.user) {
return next();
}
return res.status(401).end();
};

View File

@ -2,7 +2,7 @@ extends ../layout
block content block content
script. script.
var challengeName = 'Account View' var challengeName = 'Account View'
.panel.panel-info(ng-controller="profileValidationController") .panel.panel-info
.panel-heading.text-center Manage your account here .panel-heading.text-center Manage your account here
.panel-body .panel-body
.row .row

View File

@ -1,5 +1,7 @@
extends ../layout extends ../layout
block content block content
.bg-danger.default-border-radius
p      We are running emergency server maintenance. Your account and challenge completion will not be saved until this message goes away. Sorry about the inconvenience and thank you for your understanding.
.panel.panel-info .panel.panel-info
.panel-heading.text-center .panel-heading.text-center
h1 Challenge Map h1 Challenge Map

View File

@ -1,5 +1,7 @@
extends layout extends layout
block content block content
.bg-danger.default-border-radius
p      We are running emergency server maintenance. Your account and challenge completion will not be saved until this message goes away. Sorry about the inconvenience and thank you for your understanding.
.jumbotron .jumbotron
.text-center .text-center
h1.hug-top Code with Us h1.hug-top Code with Us

View File

@ -1,5 +1,7 @@
extends ../layout extends ../layout
block content block content
.bg-danger.default-border-radius
p      We are running emergency server maintenance. Your account and challenge completion will not be saved until this message goes away. Sorry about the inconvenience and thank you for your understanding.
.jumbotron .jumbotron
h2.text-center Scroll down and follow along with this 8-minute guide. h2.text-center Scroll down and follow along with this 8-minute guide.
br br