Skip to content
Permalink
Browse files

Add .editorconfig to enforce certain automatic behavior on all editors,

Add logic for ziplines and basejumps completion.
  • Loading branch information...
terakilobyte committed Mar 29, 2015
1 parent f6df15d commit 1fc3cffdbffebc11cfcc603d266a2d32e95b58d1
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 app.js
@@ -438,6 +438,8 @@ app.get(
coursewareController.returnIndividualCourseware
);
app.post('/completed-courseware/', coursewareController.completedCourseware);
app.post('/completed-zipline-or-basejump',
coursewareController.completedZiplineOrBasejump);

// Unique Check API route
app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername);
@@ -1,17 +1,9 @@
var _ = require('lodash'),
<<<<<<< HEAD
debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire'),
User = require('./../models/User'),
resources = require('./resources'),
R = require('ramda');
=======
debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire'),
User = require('./../models/User'),
resources = require('./resources'),
MDNlinks = require('./../seed_data/bonfireMDNlinks');
>>>>>>> upstream/master
MDNlinks = require('./../seed_data/bonfireMDNlinks');

/**
* Bonfire controller
@@ -103,34 +95,11 @@ exports.returnIndividualBonfire = function(req, res, next) {
return res.redirect('/bonfires');
}

<<<<<<< HEAD
bonfire = bonfire.pop();
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
return res.redirect('../bonfires/' + dashedNameFull);
}
=======
res.render('bonfire/show', {
completedWith: null,
title: bonfire.name,
dashedName: dashedName,
name: bonfire.name,
difficulty: Math.floor(+bonfire.difficulty),
brief: bonfire.description[0],
details: bonfire.description.slice(1),
tests: bonfire.tests,
challengeSeed: bonfire.challengeSeed,
cc: !!req.user,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
bonfires: bonfire,
bonfireHash: bonfire._id,
MDNkeys: bonfire.MDNlinks,
MDNlinks: getMDNlinks(bonfire.MDNlinks)
>>>>>>> upstream/master

res.render('bonfire/show', {
completedWith: null,
title: bonfire.name,
@@ -142,12 +111,14 @@ exports.returnIndividualBonfire = function(req, res, next) {
tests: bonfire.tests,
challengeSeed: bonfire.challengeSeed,
cc: !!req.user,
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
bonfires: bonfire,
bonfireHash: bonfire._id
bonfireHash: bonfire._id,
MDNkeys: bonfire.MDNlinks,
MDNlinks: getMDNlinks(bonfire.MDNlinks)
});
});
};
@@ -189,18 +160,18 @@ function randomString() {

/**
* Helper function to populate the MDN links array.
*/
*/

function getMDNlinks(links) {
// takes in an array of links, which are strings
var populatedLinks = [];
// 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
links.forEach(function(value, index) {
populatedLinks.push(MDNlinks[value]);
});
// for each key value, push the corresponding link from the MDNlinks object into a new array
links.forEach(function(value, index) {
populatedLinks.push(MDNlinks[value]);
});

return populatedLinks;
return populatedLinks;

};

@@ -210,15 +181,15 @@ function getMDNlinks(links) {

exports.testBonfire = function(req, res) {
var bonfireName = req.body.name,
bonfireTests = req.body.tests,
bonfireDifficulty = req.body.difficulty,
bonfireDescription = req.body.description,
bonfireChallengeSeed = req.body.challengeSeed;
bonfireTests = bonfireTests.split('\r\n');
bonfireDescription = bonfireDescription.split('\r\n');
bonfireTests.filter(getRidOfEmpties);
bonfireDescription.filter(getRidOfEmpties);
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
bonfireTests = req.body.tests,
bonfireDifficulty = req.body.difficulty,
bonfireDescription = req.body.description,
bonfireChallengeSeed = req.body.challengeSeed;
bonfireTests = bonfireTests.split('\r\n');
bonfireDescription = bonfireDescription.split('\r\n');
bonfireTests.filter(getRidOfEmpties);
bonfireDescription.filter(getRidOfEmpties);
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');

res.render('bonfire/show', {
completedWith: null,
@@ -251,15 +222,15 @@ exports.publicGenerator = function(req, res) {

exports.generateChallenge = function(req, res) {
var bonfireName = req.body.name,
bonfireTests = req.body.tests,
bonfireDifficulty = req.body.difficulty,
bonfireDescription = req.body.description,
bonfireChallengeSeed = req.body.challengeSeed;
bonfireTests = bonfireTests.split('\r\n');
bonfireDescription = bonfireDescription.split('\r\n');
bonfireTests.filter(getRidOfEmpties);
bonfireDescription.filter(getRidOfEmpties);
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
bonfireTests = req.body.tests,
bonfireDifficulty = req.body.difficulty,
bonfireDescription = req.body.description,
bonfireChallengeSeed = req.body.challengeSeed;
bonfireTests = bonfireTests.split('\r\n');
bonfireDescription = bonfireDescription.split('\r\n');
bonfireTests.filter(getRidOfEmpties);
bonfireDescription.filter(getRidOfEmpties);
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');


var response = {
@@ -100,7 +100,8 @@ exports.returnIndividualCourseware = function(req, res, next) {
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
environment: resources.whichEnvironment()
environment: resources.whichEnvironment(),
challengeType: courseware.challengeType
});
},

@@ -117,7 +118,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,

challengeType: courseware.challengeType
});
},

@@ -133,7 +134,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
challengeType: 'video'
challengeType: courseware.challengeType
});
},

@@ -160,16 +161,16 @@ exports.returnIndividualCourseware = function(req, res, next) {

exports.testCourseware = function(req, res) {
var coursewareName = req.body.name,
coursewareTests = req.body.tests,
coursewareDifficulty = req.body.difficulty,
coursewareDescription = req.body.description,
coursewareEntryPoint = req.body.challengeEntryPoint,
coursewareChallengeSeed = req.body.challengeSeed;
coursewareTests = coursewareTests.split('\r\n');
coursewareDescription = coursewareDescription.split('\r\n');
coursewareTests.filter(getRidOfEmpties);
coursewareDescription.filter(getRidOfEmpties);
coursewareChallengeSeed = coursewareChallengeSeed.replace('\r', '');
coursewareTests = req.body.tests,
coursewareDifficulty = req.body.difficulty,
coursewareDescription = req.body.description,
coursewareEntryPoint = req.body.challengeEntryPoint,
coursewareChallengeSeed = req.body.challengeSeed;
coursewareTests = coursewareTests.split('\r\n');
coursewareDescription = coursewareDescription.split('\r\n');
coursewareTests.filter(getRidOfEmpties);
coursewareDescription.filter(getRidOfEmpties);
coursewareChallengeSeed = coursewareChallengeSeed.replace('\r', '');
res.render('courseware/show', {
completedWith: null,
title: coursewareName,
@@ -233,7 +234,9 @@ exports.completedCourseware = function (req, res, next) {
req.user.completedCoursewares.push({
_id: coursewareHash,
completedDate: isCompletedDate,
name: req.body.coursewareInfo.coursewareName
name: req.body.coursewareInfo.coursewareName,
solution: null,
githubLink: null
});
var index = req.user.completedCoursewares.indexOf(coursewareHash);

@@ -247,19 +250,26 @@ exports.completedCourseware = function (req, res, next) {
return next(err);
}
if (user) {
res.send(true);
res.sendStatus(200);
}
});
};

exports.completedZiplineOrBasejump = function (req, res, next) {
var isCompletedWith = req.body.bonfireInfo.completedWith || false;
debug('Inside controller for completed zipline or basejump with data %s',
req.body.coursewareInfo);
var isCompletedWith = req.body.coursewareInfo.completedWith || false;
var isCompletedDate = Math.round(+new Date());
var coursewareHash = req.body.coursewareInfo.coursewareHash;
var solutionLink = req.body.coursewareInfo.solutionLink;
if (!solutionLink) {
// flash error and redirect
return next(new Error('No solution provided'));
var solutionLink = req.body.coursewareInfo.publicURL;
var githubLink = req.body.coursewareInfo.challengeType === 4
? req.body.coursewareInfo.githubURL : true;
if (!solutionLink || !githubLink) {
req.flash('errors', {
msg: 'You haven\'t supplied the necessary URLs for us to inspect ' +
'your work.'
});
return res.sendStatus(403);
}

if (isCompletedWith) {
@@ -286,14 +296,16 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
_id: coursewareHash,
completedWith: req.user._id,
completedDate: isCompletedDate,
solution: solutionLink
solution: solutionLink,
githubLink: githubLink
});

req.user.completedCoursewares.push({
_id: coursewareHash,
completedWith: pairedWith._id,
completedDate: isCompletedDate,
solution: solutionLink
solution: solutionLink,
githubLink: githubLink
});

req.user.save(function (err, user) {
@@ -305,7 +317,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
return next(err);
}
if (user && paired) {
return res.send(true);
return res.sendStatus(200);
}
});
});
@@ -317,10 +329,11 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
_id: coursewareHash,
completedWith: null,
completedDate: isCompletedDate,
solution: solutionLink
solution: solutionLink,
githubLink: githubLink
});

var index = req.user.uncompletedCourse.indexOf(coursewareHash);
var index = req.user.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) {
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedCoursewares.splice(index, 1);
@@ -331,8 +344,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
return next(err);
}
if (user) {
debug('Saving user');
return res.send(true);
return res.sendStatus(200);
}
});
}
@@ -347,7 +347,10 @@ var userSchema = new mongoose.Schema({
{
completedDate: Long,
_id: String,
name: String
name: String,
completedWith: String,
solution: String,
githubLink: String
}
],
currentStreak: {
Oops, something went wrong.

0 comments on commit 1fc3cff

Please sign in to comment.
You can’t perform that action at this time.