Streak display in account/show.jade, refactor courseware.json for error handling and linting
This commit is contained in:
6
app.js
6
app.js
@ -39,8 +39,6 @@ var express = require('express'),
|
|||||||
resourcesController = require('./controllers/resources'),
|
resourcesController = require('./controllers/resources'),
|
||||||
userController = require('./controllers/user'),
|
userController = require('./controllers/user'),
|
||||||
contactController = require('./controllers/contact'),
|
contactController = require('./controllers/contact'),
|
||||||
ziplineController = require('./controllers/ziplines'),
|
|
||||||
basejumpController = require('./controllers/basejumps'),
|
|
||||||
nonprofitController = require('./controllers/nonprofits'),
|
nonprofitController = require('./controllers/nonprofits'),
|
||||||
bonfireController = require('./controllers/bonfire'),
|
bonfireController = require('./controllers/bonfire'),
|
||||||
coursewareController = require('./controllers/courseware'),
|
coursewareController = require('./controllers/courseware'),
|
||||||
@ -48,7 +46,7 @@ var express = require('express'),
|
|||||||
/**
|
/**
|
||||||
* Stories
|
* Stories
|
||||||
*/
|
*/
|
||||||
storyController = require('./controllers/story');
|
storyController = require('./controllers/story'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API keys and Passport configuration.
|
* API keys and Passport configuration.
|
||||||
@ -398,8 +396,6 @@ app.post(
|
|||||||
app.all('/account', passportConf.isAuthenticated);
|
app.all('/account', passportConf.isAuthenticated);
|
||||||
app.get('/account/api', userController.getAccountAngular);
|
app.get('/account/api', userController.getAccountAngular);
|
||||||
|
|
||||||
app.get('/user/streak', userController.getStreak);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API routes
|
* API routes
|
||||||
*/
|
*/
|
||||||
|
@ -1,142 +1,145 @@
|
|||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
debug = require('debug')('freecc:cntr:bonfires'),
|
debug = require('debug')('freecc:cntr:bonfires'),
|
||||||
Bonfire = require('./../models/Bonfire'),
|
Bonfire = require('./../models/Bonfire'),
|
||||||
User = require('./../models/User'),
|
User = require('./../models/User'),
|
||||||
resources = require('./resources'),
|
resources = require('./resources'),
|
||||||
R = require('ramda');
|
R = require('ramda');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bonfire controller
|
* Bonfire controller
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.showAllBonfires = function(req, res) {
|
exports.showAllBonfires = function(req, res) {
|
||||||
var completedBonfires = req.user.completedBonfires.map(function(elem) {
|
var completedBonfires = req.user.completedBonfires.map(function(elem) {
|
||||||
return elem._id;
|
return elem._id;
|
||||||
});
|
});
|
||||||
|
|
||||||
var noDuplicateBonfires = R.uniq(completedBonfires);
|
var noDuplicateBonfires = R.uniq(completedBonfires);
|
||||||
var data = {};
|
var data = {};
|
||||||
data.bonfireList = resources.allBonfireNames();
|
data.bonfireList = resources.allBonfireNames();
|
||||||
data.completedList = noDuplicateBonfires;
|
data.completedList = noDuplicateBonfires;
|
||||||
res.send(data);
|
res.send(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.index = function(req, res) {
|
exports.index = function(req, res) {
|
||||||
res.render('bonfire/show.jade', {
|
res.render('bonfire/show.jade', {
|
||||||
completedWith: null,
|
completedWith: null,
|
||||||
title: 'Bonfire Playground',
|
title: 'Bonfire Playground',
|
||||||
name: 'Bonfire Playground',
|
name: 'Bonfire Playground',
|
||||||
difficulty: 0,
|
difficulty: 0,
|
||||||
brief: 'Feel free to play around!',
|
brief: 'Feel free to play around!',
|
||||||
details: '',
|
details: '',
|
||||||
tests: [],
|
tests: [],
|
||||||
challengeSeed: '',
|
challengeSeed: '',
|
||||||
cc: req.user ? req.user.bonfiresHash : undefined,
|
cc: req.user ? req.user.bonfiresHash : undefined,
|
||||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||||
verb: resources.randomVerb(),
|
verb: resources.randomVerb(),
|
||||||
phrase: resources.randomPhrase(),
|
phrase: resources.randomPhrase(),
|
||||||
compliments: resources.randomCompliment(),
|
compliments: resources.randomCompliment(),
|
||||||
bonfires: [],
|
bonfires: [],
|
||||||
bonfireHash: 'test'
|
bonfireHash: 'test'
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.returnNextBonfire = function(req, res) {
|
exports.returnNextBonfire = function(req, res, next) {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
return res.redirect('../bonfires/meet-bonfire');
|
return res.redirect('../bonfires/meet-bonfire');
|
||||||
|
}
|
||||||
|
var completed = req.user.completedBonfires.map(function (elem) {
|
||||||
|
return elem._id;
|
||||||
|
});
|
||||||
|
|
||||||
|
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function (elem) {
|
||||||
|
if (completed.indexOf(elem) === -1) {
|
||||||
|
return elem;
|
||||||
}
|
}
|
||||||
var completed = req.user.completedBonfires.map(function (elem) {
|
});
|
||||||
return elem._id;
|
req.user.save();
|
||||||
});
|
|
||||||
|
|
||||||
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function (elem) {
|
var uncompletedBonfires = req.user.uncompletedBonfires;
|
||||||
if (completed.indexOf(elem) === -1) {
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
req.user.save();
|
|
||||||
|
|
||||||
var uncompletedBonfires = req.user.uncompletedBonfires;
|
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
|
||||||
|
displayedBonfires.exec(function(err, bonfire) {
|
||||||
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
|
if (err) {
|
||||||
displayedBonfires.exec(function(err, bonfire) {
|
return next(err);
|
||||||
if (err) {
|
}
|
||||||
next(err);
|
bonfire = bonfire.pop();
|
||||||
}
|
if (bonfire === undefined) {
|
||||||
bonfire = bonfire.pop();
|
req.flash('errors', {
|
||||||
if (bonfire === undefined) {
|
msg: "It looks like you've completed all the bonfires we have available. Good job!"
|
||||||
req.flash('errors', {
|
});
|
||||||
msg: "It looks like you've completed all the bonfires we have available. Good job!"
|
return res.redirect('../bonfires/meet-bonfire');
|
||||||
});
|
}
|
||||||
return res.redirect('../bonfires/meet-bonfire');
|
var nameString = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||||
}
|
return res.redirect('../bonfires/' + nameString);
|
||||||
nameString = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
});
|
||||||
return res.redirect('../bonfires/' + nameString);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.returnIndividualBonfire = function(req, res, next) {
|
exports.returnIndividualBonfire = function(req, res, next) {
|
||||||
var dashedName = req.params.bonfireName;
|
var dashedName = req.params.bonfireName;
|
||||||
|
|
||||||
bonfireName = dashedName.replace(/\-/g, ' ');
|
var bonfireName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
Bonfire.find({"name" : new RegExp(bonfireName, 'i')}, function(err, bonfire) {
|
Bonfire.find({'name': new RegExp(bonfireName, 'i')}, function(err, bonfire) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (bonfire.length < 1) {
|
if (bonfire.length < 1) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.redirect('/bonfires');
|
return res.redirect('/bonfires');
|
||||||
}
|
}
|
||||||
|
|
||||||
bonfire = bonfire.pop();
|
bonfire = bonfire.pop();
|
||||||
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||||
if (dashedNameFull != dashedName) {
|
if (dashedNameFull != dashedName) {
|
||||||
return res.redirect('../bonfires/' + dashedNameFull);
|
return res.redirect('../bonfires/' + dashedNameFull);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.render('bonfire/show', {
|
res.render('bonfire/show', {
|
||||||
completedWith: null,
|
completedWith: null,
|
||||||
title: bonfire.name,
|
title: bonfire.name,
|
||||||
dashedName: dashedName,
|
dashedName: dashedName,
|
||||||
name: bonfire.name,
|
name: bonfire.name,
|
||||||
difficulty: Math.floor(+bonfire.difficulty),
|
difficulty: Math.floor(+bonfire.difficulty),
|
||||||
brief: bonfire.description[0],
|
brief: bonfire.description[0],
|
||||||
details: bonfire.description.slice(1),
|
details: bonfire.description.slice(1),
|
||||||
tests: bonfire.tests,
|
tests: bonfire.tests,
|
||||||
challengeSeed: bonfire.challengeSeed,
|
challengeSeed: bonfire.challengeSeed,
|
||||||
cc: !!req.user,
|
cc: !!req.user,
|
||||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||||
verb: resources.randomVerb(),
|
verb: resources.randomVerb(),
|
||||||
phrase: resources.randomPhrase(),
|
phrase: resources.randomPhrase(),
|
||||||
compliment: resources.randomCompliment(),
|
compliment: resources.randomCompliment(),
|
||||||
bonfires: bonfire,
|
bonfires: bonfire,
|
||||||
bonfireHash: bonfire._id
|
bonfireHash: bonfire._id
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bonfire generator
|
* Bonfire Generator
|
||||||
|
* @param req Request Object
|
||||||
|
* @param res Response Object
|
||||||
|
* @returns void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.returnGenerator = function(req, res) {
|
exports.returnGenerator = function(req, res) {
|
||||||
res.render('bonfire/generator', {
|
res.render('bonfire/generator', {
|
||||||
title: null,
|
title: null,
|
||||||
name: null,
|
name: null,
|
||||||
difficulty: null,
|
difficulty: null,
|
||||||
brief: null,
|
brief: null,
|
||||||
details: null,
|
details: null,
|
||||||
tests: null,
|
tests: null,
|
||||||
challengeSeed: null,
|
challengeSeed: null,
|
||||||
bonfireHash: randomString()
|
bonfireHash: randomString()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,162 +147,164 @@ exports.returnGenerator = function(req, res) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function randomString() {
|
function randomString() {
|
||||||
var chars = "0123456789abcdef";
|
var chars = '0123456789abcdef';
|
||||||
var string_length = 23;
|
var string_length = 23;
|
||||||
var randomstring = 'a';
|
var randomstring = 'a';
|
||||||
for (var i=0; i<string_length; i++) {
|
for (var i = 0; i < string_length; i++) {
|
||||||
var rnum = Math.floor(Math.random() * chars.length);
|
var rnum = Math.floor(Math.random() * chars.length);
|
||||||
randomstring += chars.substring(rnum,rnum+1);
|
randomstring += chars.substring(rnum, rnum + 1);
|
||||||
}
|
}
|
||||||
return randomstring;
|
return randomstring;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.testBonfire = function(req, res) {
|
exports.testBonfire = function(req, res) {
|
||||||
var bonfireName = req.body.name,
|
var bonfireName = req.body.name,
|
||||||
bonfireTests = req.body.tests,
|
bonfireTests = req.body.tests,
|
||||||
bonfireDifficulty = req.body.difficulty,
|
bonfireDifficulty = req.body.difficulty,
|
||||||
bonfireDescription = req.body.description,
|
bonfireDescription = req.body.description,
|
||||||
bonfireChallengeSeed = req.body.challengeSeed;
|
bonfireChallengeSeed = req.body.challengeSeed;
|
||||||
bonfireTests = bonfireTests.split('\r\n');
|
bonfireTests = bonfireTests.split('\r\n');
|
||||||
bonfireDescription = bonfireDescription.split('\r\n');
|
bonfireDescription = bonfireDescription.split('\r\n');
|
||||||
bonfireTests.filter(getRidOfEmpties);
|
bonfireTests.filter(getRidOfEmpties);
|
||||||
bonfireDescription.filter(getRidOfEmpties);
|
bonfireDescription.filter(getRidOfEmpties);
|
||||||
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
||||||
res.render('bonfire/show', {
|
|
||||||
completedWith: null,
|
res.render('bonfire/show', {
|
||||||
title: bonfireName,
|
completedWith: null,
|
||||||
name: bonfireName,
|
title: bonfireName,
|
||||||
difficulty: +bonfireDifficulty,
|
name: bonfireName,
|
||||||
brief: bonfireDescription[0],
|
difficulty: +bonfireDifficulty,
|
||||||
details: bonfireDescription.slice(1),
|
brief: bonfireDescription[0],
|
||||||
tests: bonfireTests,
|
details: bonfireDescription.slice(1),
|
||||||
challengeSeed: bonfireChallengeSeed,
|
tests: bonfireTests,
|
||||||
cc: req.user ? req.user.bonfiresHash : undefined,
|
challengeSeed: bonfireChallengeSeed,
|
||||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
cc: req.user ? req.user.bonfiresHash : undefined,
|
||||||
verb: resources.randomVerb(),
|
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||||
phrase: resources.randomPhrase(),
|
verb: resources.randomVerb(),
|
||||||
compliment: resources.randomCompliment(),
|
phrase: resources.randomPhrase(),
|
||||||
bonfires: [],
|
compliment: resources.randomCompliment(),
|
||||||
bonfireHash: "test"
|
bonfires: [],
|
||||||
});
|
bonfireHash: 'test'
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function getRidOfEmpties(elem) {
|
function getRidOfEmpties(elem) {
|
||||||
if (elem.length > 0) {
|
if (elem.length > 0) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.publicGenerator = function(req, res) {
|
exports.publicGenerator = function(req, res) {
|
||||||
res.render('bonfire/public-generator');
|
res.render('bonfire/public-generator');
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChallenge = function(req, res) {
|
exports.generateChallenge = function(req, res) {
|
||||||
var bonfireName = req.body.name,
|
var bonfireName = req.body.name,
|
||||||
bonfireTests = req.body.tests,
|
bonfireTests = req.body.tests,
|
||||||
bonfireDifficulty = req.body.difficulty,
|
bonfireDifficulty = req.body.difficulty,
|
||||||
bonfireDescription = req.body.description,
|
bonfireDescription = req.body.description,
|
||||||
bonfireChallengeSeed = req.body.challengeSeed;
|
bonfireChallengeSeed = req.body.challengeSeed;
|
||||||
bonfireTests = bonfireTests.split('\r\n');
|
bonfireTests = bonfireTests.split('\r\n');
|
||||||
bonfireDescription = bonfireDescription.split('\r\n');
|
bonfireDescription = bonfireDescription.split('\r\n');
|
||||||
bonfireTests.filter(getRidOfEmpties);
|
bonfireTests.filter(getRidOfEmpties);
|
||||||
bonfireDescription.filter(getRidOfEmpties);
|
bonfireDescription.filter(getRidOfEmpties);
|
||||||
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
||||||
|
|
||||||
|
|
||||||
var response = {
|
var response = {
|
||||||
_id: randomString(),
|
_id: randomString(),
|
||||||
name: bonfireName,
|
name: bonfireName,
|
||||||
difficulty: bonfireDifficulty,
|
difficulty: bonfireDifficulty,
|
||||||
description: bonfireDescription,
|
description: bonfireDescription,
|
||||||
challengeSeed: bonfireChallengeSeed,
|
challengeSeed: bonfireChallengeSeed,
|
||||||
tests: bonfireTests
|
tests: bonfireTests
|
||||||
};
|
};
|
||||||
res.send(response);
|
res.send(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.completedBonfire = function (req, res) {
|
exports.completedBonfire = function (req, res, next) {
|
||||||
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
|
var isCompletedWith = req.body.bonfireInfo.completedWith || '';
|
||||||
var isCompletedDate = Math.round(+new Date());
|
var isCompletedDate = Math.round(+new Date());
|
||||||
var bonfireHash = req.body.bonfireInfo.bonfireHash;
|
var bonfireHash = req.body.bonfireInfo.bonfireHash;
|
||||||
var isSolution = req.body.bonfireInfo.solution;
|
var isSolution = req.body.bonfireInfo.solution;
|
||||||
|
|
||||||
if (isCompletedWith) {
|
|
||||||
var paired = User.find({"profile.username": isCompletedbWith.toLowerCase()}).limit(1);
|
|
||||||
paired.exec(function (err, pairedWith) {
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
} else {
|
|
||||||
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
|
||||||
if (index > -1) {
|
|
||||||
|
|
||||||
req.user.progressTimestamps.push(Date.now() || 0);
|
|
||||||
req.user.uncompletedBonfires.splice(index, 1)
|
|
||||||
}
|
|
||||||
pairedWith = pairedWith.pop();
|
|
||||||
|
|
||||||
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
|
|
||||||
if (index > -1) {
|
|
||||||
|
|
||||||
pairedWith.progressTimestamps.push(Date.now() || 0);
|
|
||||||
pairedWith.uncompletedBonfires.splice(index, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pairedWith.completedBonfires.push({
|
|
||||||
_id: bonfireHash,
|
|
||||||
completedWith: req.user._id,
|
|
||||||
completedDate: isCompletedDate,
|
|
||||||
solution: isSolution
|
|
||||||
});
|
|
||||||
|
|
||||||
req.user.completedBonfires.push({
|
|
||||||
_id: bonfireHash,
|
|
||||||
completedWith: pairedWith._id,
|
|
||||||
completedDate: isCompletedDate,
|
|
||||||
solution: isSolution
|
|
||||||
});
|
|
||||||
|
|
||||||
req.user.save(function (err, user) {
|
|
||||||
pairedWith.save(function (err, paired) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
if (user && paired) {
|
|
||||||
res.send(true);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
|
|
||||||
req.user.completedBonfires.push({
|
|
||||||
_id: bonfireHash,
|
|
||||||
completedWith: null,
|
|
||||||
completedDate: isCompletedDate,
|
|
||||||
solution: isSolution
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (isCompletedWith) {
|
||||||
|
var paired = User.find({'profile.username': isCompletedWith
|
||||||
|
.toLowerCase()}).limit(1);
|
||||||
|
paired.exec(function (err, pairedWith) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
} else {
|
||||||
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
|
req.user.uncompletedBonfires.splice(index, 1);
|
||||||
|
}
|
||||||
|
pairedWith = pairedWith.pop();
|
||||||
|
|
||||||
|
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
|
||||||
|
if (index > -1) {
|
||||||
|
pairedWith.progressTimestamps.push(Date.now() || 0);
|
||||||
|
pairedWith.uncompletedBonfires.splice(index, 1);
|
||||||
|
|
||||||
req.user.progressTimestamps.push(Date.now() || 0);
|
|
||||||
req.user.uncompletedBonfires.splice(index, 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.user.save(function (err, user) {
|
pairedWith.completedBonfires.push({
|
||||||
if (err) {
|
_id: bonfireHash,
|
||||||
throw err;
|
completedWith: req.user._id,
|
||||||
}
|
completedDate: isCompletedDate,
|
||||||
if (user) {
|
solution: isSolution
|
||||||
debug('Saving user');
|
|
||||||
res.send(true)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
req.user.completedBonfires.push({
|
||||||
|
_id: bonfireHash,
|
||||||
|
completedWith: pairedWith._id,
|
||||||
|
completedDate: isCompletedDate,
|
||||||
|
solution: isSolution
|
||||||
|
});
|
||||||
|
|
||||||
|
req.user.save(function (err, user) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
pairedWith.save(function (err, paired) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (user && paired) {
|
||||||
|
res.send(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
req.user.completedBonfires.push({
|
||||||
|
_id: bonfireHash,
|
||||||
|
completedWith: null,
|
||||||
|
completedDate: isCompletedDate,
|
||||||
|
solution: isSolution
|
||||||
|
});
|
||||||
|
|
||||||
|
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||||
|
if (index > -1) {
|
||||||
|
|
||||||
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
|
req.user.uncompletedBonfires.splice(index, 1);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
req.user.save(function (err, user) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (user) {
|
||||||
|
debug('Saving user');
|
||||||
|
res.send(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
debug = require('debug')('freecc:cntr:courseware'),
|
debug = require('debug')('freecc:cntr:courseware'),
|
||||||
Courseware = require('./../models/Courseware'),
|
Courseware = require('./../models/Courseware'),
|
||||||
User = require('./../models/User'),
|
User = require('./../models/User'),
|
||||||
resources = require('./resources'),
|
resources = require('./resources'),
|
||||||
R = require('ramda'),
|
R = require('ramda'),
|
||||||
moment = require('moment');
|
moment = require('moment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Courseware controller
|
* Courseware controller
|
||||||
@ -22,7 +22,7 @@ exports.showAllCoursewares = function(req, res) {
|
|||||||
res.send(data);
|
res.send(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.returnNextCourseware = function(req, res) {
|
exports.returnNextCourseware = function(req, res, next) {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
||||||
}
|
}
|
||||||
@ -30,7 +30,8 @@ exports.returnNextCourseware = function(req, res) {
|
|||||||
return elem._id;
|
return elem._id;
|
||||||
});
|
});
|
||||||
|
|
||||||
req.user.uncompletedCoursewares = resources.allCoursewareIds().filter(function (elem) {
|
req.user.uncompletedCoursewares = resources.allCoursewareIds()
|
||||||
|
.filter(function (elem) {
|
||||||
if (completed.indexOf(elem) === -1) {
|
if (completed.indexOf(elem) === -1) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
@ -40,16 +41,17 @@ exports.returnNextCourseware = function(req, res) {
|
|||||||
var uncompletedCoursewares = req.user.uncompletedCoursewares.shift();
|
var uncompletedCoursewares = req.user.uncompletedCoursewares.shift();
|
||||||
|
|
||||||
|
|
||||||
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares});
|
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares});
|
||||||
displayedCoursewares.exec(function(err, courseware) {
|
displayedCoursewares.exec(function(err, courseware) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
courseware = courseware.pop();
|
courseware = courseware.pop();
|
||||||
if (courseware === undefined) {
|
if (courseware === undefined) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "It looks like you've completed all the courses we have available. Good job!"
|
msg: "It looks like you've completed all the courses we have " +
|
||||||
|
"available. Good job!"
|
||||||
});
|
});
|
||||||
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
||||||
}
|
}
|
||||||
@ -61,16 +63,18 @@ exports.returnNextCourseware = function(req, res) {
|
|||||||
exports.returnIndividualCourseware = function(req, res, next) {
|
exports.returnIndividualCourseware = function(req, res, next) {
|
||||||
var dashedName = req.params.coursewareName;
|
var dashedName = req.params.coursewareName;
|
||||||
|
|
||||||
coursewareName = dashedName.replace(/\-/g, ' ');
|
var coursewareName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
Courseware.find({"name" : new RegExp(coursewareName, 'i')}, function(err, courseware) {
|
Courseware.find({'name': new RegExp(coursewareName, 'i')},
|
||||||
|
function(err, courseware) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
// Handle not found
|
// Handle not found
|
||||||
if (courseware.length < 1) {
|
if (courseware.length < 1) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "404: We couldn't find a challenge with that name. Please double check the name."
|
msg: "404: We couldn't find a challenge with that name. " +
|
||||||
|
"Please double check the name."
|
||||||
});
|
});
|
||||||
return res.redirect('/challenges');
|
return res.redirect('/challenges');
|
||||||
}
|
}
|
||||||
@ -83,7 +87,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var challengeType = {
|
var challengeType = {
|
||||||
0 : function() {
|
0: function() {
|
||||||
res.render('coursewares/showHTML', {
|
res.render('coursewares/showHTML', {
|
||||||
title: courseware.name,
|
title: courseware.name,
|
||||||
dashedName: dashedName,
|
dashedName: dashedName,
|
||||||
@ -100,7 +104,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
1 : function() {
|
1: function() {
|
||||||
res.render('coursewares/showJS', {
|
res.render('coursewares/showJS', {
|
||||||
title: courseware.name,
|
title: courseware.name,
|
||||||
dashedName: dashedName,
|
dashedName: dashedName,
|
||||||
@ -134,7 +138,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
3: function() {
|
3: function() {
|
||||||
res.render('coursewares/showVideo', {
|
res.render('coursewares/showZipline', {
|
||||||
title: courseware.name,
|
title: courseware.name,
|
||||||
dashedName: dashedName,
|
dashedName: dashedName,
|
||||||
name: courseware.name,
|
name: courseware.name,
|
||||||
@ -150,7 +154,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
4: function() {
|
4: function() {
|
||||||
res.render('coursewares/showVideo', {
|
res.render('coursewares/showBasejump', {
|
||||||
title: courseware.name,
|
title: courseware.name,
|
||||||
dashedName: dashedName,
|
dashedName: dashedName,
|
||||||
name: courseware.name,
|
name: courseware.name,
|
||||||
@ -173,11 +177,11 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
|||||||
|
|
||||||
exports.testCourseware = function(req, res) {
|
exports.testCourseware = function(req, res) {
|
||||||
var coursewareName = req.body.name,
|
var coursewareName = req.body.name,
|
||||||
coursewareTests = req.body.tests,
|
coursewareTests = req.body.tests,
|
||||||
coursewareDifficulty = req.body.difficulty,
|
coursewareDifficulty = req.body.difficulty,
|
||||||
coursewareDescription = req.body.description,
|
coursewareDescription = req.body.description,
|
||||||
coursewareEntryPoint = req.body.challengeEntryPoint,
|
coursewareEntryPoint = req.body.challengeEntryPoint,
|
||||||
coursewareChallengeSeed = req.body.challengeSeed;
|
coursewareChallengeSeed = req.body.challengeSeed;
|
||||||
coursewareTests = coursewareTests.split('\r\n');
|
coursewareTests = coursewareTests.split('\r\n');
|
||||||
coursewareDescription = coursewareDescription.split('\r\n');
|
coursewareDescription = coursewareDescription.split('\r\n');
|
||||||
coursewareTests.filter(getRidOfEmpties);
|
coursewareTests.filter(getRidOfEmpties);
|
||||||
@ -190,8 +194,8 @@ exports.testCourseware = function(req, res) {
|
|||||||
difficulty: +coursewareDifficulty,
|
difficulty: +coursewareDifficulty,
|
||||||
brief: coursewareDescription[0],
|
brief: coursewareDescription[0],
|
||||||
details: coursewareDescription.slice(1),
|
details: coursewareDescription.slice(1),
|
||||||
tests: coursewareTests,
|
tests: coursewareTests,
|
||||||
challengeSeed: coursewareChallengeSeed,
|
challengeSeed: coursewareChallengeSeed,
|
||||||
challengeEntryPoint: coursewareEntryPoint,
|
challengeEntryPoint: coursewareEntryPoint,
|
||||||
cc: req.user ? req.user.coursewaresHash : undefined,
|
cc: req.user ? req.user.coursewaresHash : undefined,
|
||||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||||
@ -199,7 +203,7 @@ exports.testCourseware = function(req, res) {
|
|||||||
phrase: resources.randomPhrase(),
|
phrase: resources.randomPhrase(),
|
||||||
compliment: resources.randomCompliment(),
|
compliment: resources.randomCompliment(),
|
||||||
coursewares: [],
|
coursewares: [],
|
||||||
coursewareHash: "test"
|
coursewareHash: 'test'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -207,7 +211,7 @@ function getRidOfEmpties(elem) {
|
|||||||
if (elem.length > 0) {
|
if (elem.length > 0) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.publicGenerator = function(req, res) {
|
exports.publicGenerator = function(req, res) {
|
||||||
res.render('courseware/public-generator');
|
res.render('courseware/public-generator');
|
||||||
@ -215,11 +219,11 @@ exports.publicGenerator = function(req, res) {
|
|||||||
|
|
||||||
exports.generateChallenge = function(req, res) {
|
exports.generateChallenge = function(req, res) {
|
||||||
var coursewareName = req.body.name,
|
var coursewareName = req.body.name,
|
||||||
coursewareTests = req.body.tests,
|
coursewareTests = req.body.tests,
|
||||||
coursewareDifficulty = req.body.difficulty,
|
coursewareDifficulty = req.body.difficulty,
|
||||||
coursewareDescription = req.body.description,
|
coursewareDescription = req.body.description,
|
||||||
coursewareEntryPoint = req.body.challengeEntryPoint,
|
coursewareEntryPoint = req.body.challengeEntryPoint,
|
||||||
coursewareChallengeSeed = req.body.challengeSeed;
|
coursewareChallengeSeed = req.body.challengeSeed;
|
||||||
coursewareTests = coursewareTests.split('\r\n');
|
coursewareTests = coursewareTests.split('\r\n');
|
||||||
coursewareDescription = coursewareDescription.split('\r\n');
|
coursewareDescription = coursewareDescription.split('\r\n');
|
||||||
coursewareTests.filter(getRidOfEmpties);
|
coursewareTests.filter(getRidOfEmpties);
|
||||||
@ -243,34 +247,26 @@ exports.completedCourseware = function (req, res, next) {
|
|||||||
var isCompletedDate = Math.round(+new Date());
|
var isCompletedDate = Math.round(+new Date());
|
||||||
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
||||||
|
|
||||||
debug('this is the coursewarehash we got', coursewareHash);
|
|
||||||
|
|
||||||
req.user.completedCoursewares.push({
|
req.user.completedCoursewares.push({
|
||||||
_id: coursewareHash,
|
_id: coursewareHash,
|
||||||
completedDate: isCompletedDate,
|
completedDate: isCompletedDate,
|
||||||
name: req.body.coursewareInfo.coursewareName
|
name: req.body.coursewareInfo.coursewareName
|
||||||
});
|
});
|
||||||
|
|
||||||
var index = req.user.completedCoursewares.indexOf(coursewareHash);
|
var index = req.user.completedCoursewares.indexOf(coursewareHash);
|
||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
|
|
||||||
req.user.progressTimestamps.push(Date.now() || 0);
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
req.user.uncompletedCoursewares.splice(index, 1);
|
req.user.uncompletedCoursewares.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.completedBasejump = function (req, res, next) {
|
req.user.save(function (err, user) {
|
||||||
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
|
if (err) {
|
||||||
var isCompletedDate = Math.round(+new Date());
|
return next(err);
|
||||||
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
|
||||||
var solutionLink = req.body.coursewareInfo.solutionLink;
|
|
||||||
if(!solutionLink) {
|
|
||||||
// flash error and redirect
|
|
||||||
}
|
}
|
||||||
if (user) {
|
if (user) {
|
||||||
res.send(true);
|
res.send(true);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.completedZiplineOrBasejump = function (req, res, next) {
|
exports.completedZiplineOrBasejump = function (req, res, next) {
|
||||||
|
@ -196,50 +196,6 @@ exports.postEmailSignup = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* For Calendar display
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.getStreak = function(req, res, next) {
|
|
||||||
|
|
||||||
req.user.progressTimestamps = req.user.progressTimestamps.sort(function(a, b) {
|
|
||||||
return a - b;
|
|
||||||
});
|
|
||||||
|
|
||||||
var timeObject = Object.create(null);
|
|
||||||
R.forEach(function(time) {
|
|
||||||
timeObject[moment(time).format('YYYY-MM-DD')] = time;
|
|
||||||
}, req.user.progressTimestamps);
|
|
||||||
|
|
||||||
var tmpLongest = 1;
|
|
||||||
var timeKeys = R.keys(timeObject);
|
|
||||||
for (var i = 1; i <= timeKeys.length; i++) {
|
|
||||||
if (moment(timeKeys[i - 1]).add(1, 'd').toString()
|
|
||||||
=== moment(timeKeys[i]).toString()) {
|
|
||||||
tmpLongest++;
|
|
||||||
if (tmpLongest > req.user.currentStreak) {
|
|
||||||
req.user.currentStreak = tmpLongest;
|
|
||||||
}
|
|
||||||
if ( req.user.currentStreak > req.user.longestStreak) {
|
|
||||||
req.user.longestStreak = req.user.currentStreak;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
req.user.save(function(err) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
s
|
|
||||||
var payload = {
|
|
||||||
longest: req.user.longestStreak,
|
|
||||||
timeObject: timeObject
|
|
||||||
};
|
|
||||||
|
|
||||||
return res.send(payload);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /account
|
* GET /account
|
||||||
* Profile page.
|
* Profile page.
|
||||||
@ -314,6 +270,36 @@ exports.returnUser = function(req, res, next) {
|
|||||||
if (user[0]) {
|
if (user[0]) {
|
||||||
var user = user[0];
|
var user = user[0];
|
||||||
|
|
||||||
|
user.progressTimestamps = user.progressTimestamps.sort(function(a, b) {
|
||||||
|
return a - b;
|
||||||
|
});
|
||||||
|
|
||||||
|
var timeObject = Object.create(null);
|
||||||
|
R.forEach(function(time) {
|
||||||
|
timeObject[moment(time).format('YYYY-MM-DD')] = time;
|
||||||
|
}, user.progressTimestamps);
|
||||||
|
|
||||||
|
var tmpLongest = 1;
|
||||||
|
var timeKeys = R.keys(timeObject);
|
||||||
|
for (var i = 1; i <= timeKeys.length; i++) {
|
||||||
|
if (moment(timeKeys[i - 1]).add(1, 'd').toString()
|
||||||
|
=== moment(timeKeys[i]).toString()) {
|
||||||
|
tmpLongest++;
|
||||||
|
if (tmpLongest > user.currentStreak) {
|
||||||
|
user.currentStreak = tmpLongest;
|
||||||
|
}
|
||||||
|
if ( user.currentStreak > user.longestStreak) {
|
||||||
|
user.longestStreak = user.currentStreak;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user.save(function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
var progressTimestamps = user.progressTimestamps;
|
var progressTimestamps = user.progressTimestamps;
|
||||||
for (var i = 0; i < progressTimestamps.length; i++) {
|
for (var i = 0; i < progressTimestamps.length; i++) {
|
||||||
@ -344,7 +330,9 @@ exports.returnUser = function(req, res, next) {
|
|||||||
website3Image: user.portfolio.website3Image,
|
website3Image: user.portfolio.website3Image,
|
||||||
ch: user.challengesHash,
|
ch: user.challengesHash,
|
||||||
calender: data,
|
calender: data,
|
||||||
moment: moment
|
moment: moment,
|
||||||
|
longestStreak: user.longestStreak,
|
||||||
|
currentStreak: user.currentStreak
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
"moment": "^2.8.4",
|
"moment": "^2.8.4",
|
||||||
"mongodb": "^1.4.33",
|
"mongodb": "^1.4.33",
|
||||||
"mongoose": "^4.0.0",
|
"mongoose": "^4.0.0",
|
||||||
|
"mongoose-long": "0.0.2",
|
||||||
"morgan": "^1.5.0",
|
"morgan": "^1.5.0",
|
||||||
"newrelic": "^1.13.3",
|
"newrelic": "^1.13.3",
|
||||||
"nodemailer": "^1.3.0",
|
"nodemailer": "^1.3.0",
|
||||||
|
@ -21,13 +21,13 @@ block content
|
|||||||
img.img-center.img-responsive.public-profile-img(src='https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png')
|
img.img-center.img-responsive.public-profile-img(src='https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png')
|
||||||
h1.text-center.negative-5
|
h1.text-center.negative-5
|
||||||
- if (twitterHandle)
|
- if (twitterHandle)
|
||||||
a.ion-social-twitter.text-primary(title="@#{username}'s Twitter Profile", href="http://twitter.com/#{twitterHandle}", target='_blank')
|
a.ion-social-twitter.text-primary(title="@#{username}'s Twitter Profile", href="http://twitter.com/#{twitterHandle}", target='_blank')
|
||||||
- if (githubProfile)
|
- if (githubProfile)
|
||||||
a.ion-social-github.text-primary(title="@#{username}'s GitHub Profile", href=githubProfile, target='_blank')
|
a.ion-social-github.text-primary(title="@#{username}'s GitHub Profile", href=githubProfile, target='_blank')
|
||||||
- if (linkedinProfile)
|
- if (linkedinProfile)
|
||||||
a.ion-social-linkedin.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedinProfile, target='_blank')
|
a.ion-social-linkedin.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedinProfile, target='_blank')
|
||||||
- if (codepenProfile)
|
- if (codepenProfile)
|
||||||
a.ion-social-codepen.text-primary(title="@#{username}'s CodePen Profile", href=codepenProfile, target='_blank')
|
a.ion-social-codepen.text-primary(title="@#{username}'s CodePen Profile", href=codepenProfile, target='_blank')
|
||||||
.visible-md.visible-lg
|
.visible-md.visible-lg
|
||||||
.col-xs-12.col-sm-12.col-md-4.text-justify
|
.col-xs-12.col-sm-12.col-md-4.text-justify
|
||||||
h1.flat-top.wrappable= name
|
h1.flat-top.wrappable= name
|
||||||
@ -118,4 +118,17 @@ block content
|
|||||||
start: new Date().setDate(new Date().getDate() - 90),
|
start: new Date().setDate(new Date().getDate() - 90),
|
||||||
legendColors: ["#cccccc", "#215f1e"],
|
legendColors: ["#cccccc", "#215f1e"],
|
||||||
legend: [1, 2, 3]
|
legend: [1, 2, 3]
|
||||||
});
|
});
|
||||||
|
.row
|
||||||
|
.hidden-xs.col-sm-12.text-center
|
||||||
|
.row
|
||||||
|
h3.col-sm-6.text-center
|
||||||
|
.center-block.
|
||||||
|
#{longestStreak}
|
||||||
|
.center-block.
|
||||||
|
Longest Streak
|
||||||
|
h3.col-sm-6.text-center
|
||||||
|
.center-block.
|
||||||
|
#{currentStreak}
|
||||||
|
.center-block.
|
||||||
|
Current Streak
|
Reference in New Issue
Block a user