diff --git a/app.js b/app.js index abfa3e5685..cfc2d71966 100644 --- a/app.js +++ b/app.js @@ -287,8 +287,6 @@ app.post('/completed-bonfire/', function (req, res) { var isCompletedDate = Math.round(+new Date() / 1000); var bonfireHash = req.body.bonfireInfo.bonfireHash; var isSolution = req.body.bonfireInfo.solution; - // TODO - debug(isCompletedWith, 'Is completed with'); if (isCompletedWith) { var paired = User.find({"profile.username": isCompletedWith}).limit(1); @@ -328,14 +326,14 @@ app.post('/completed-bonfire/', function (req, res) { throw err; } if (user && paired) { - res.redirect('/bonfires'); + res.send(true); } }) }); - } }) } else { + req.user.completedBonfires.push({ _id: bonfireHash, completedWith: null, @@ -344,21 +342,20 @@ app.post('/completed-bonfire/', function (req, res) { }) var index = req.user.uncompletedBonfires.indexOf(bonfireHash); - if (index > -1) { req.user.uncompletedBonfires.splice(index,1) } + req.user.save(function(err, user) { if (err) { throw err; } if (user) { - res.redirect('/bonfires'); + debug('Saving user'); + res.send(true) } }); - } - }); // Unique Check API route diff --git a/controllers/bonfire.js b/controllers/bonfire.js index 5025e68cf7..d9a2c7967d 100644 --- a/controllers/bonfire.js +++ b/controllers/bonfire.js @@ -37,7 +37,7 @@ exports.returnNextBonfire = function(req, res, next) { return res.redirect('bonfires/meet-bonfire'); } var currentTime = parseInt(+new Date() / 1000); - if (currentTime - req.user.lastContentSync > 86400) { + if (currentTime - req.user.lastContentSync > 10) { req.user.lastContentSync = currentTime; var completed = req.user.completedBonfires.map(function (elem) { return elem._id; diff --git a/public/js/lib/bonfire/bonfireFramework.js b/public/js/lib/bonfire/bonfireFramework.js index e7fc90cf28..83a8742b5c 100644 --- a/public/js/lib/bonfire/bonfireFramework.js +++ b/public/js/lib/bonfire/bonfireFramework.js @@ -214,10 +214,12 @@ var runTests = function(err, data) { } } }); - } - if (allTestsPassed) { - allTestsPassed = false; - showCompletion(); + + if (allTestsPassed) { + allTestsPassed = false; + showCompletion(); + } + } }; diff --git a/public/js/main.js b/public/js/main.js index b8f32d468a..16c03987a9 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -39,21 +39,33 @@ $(document).ready(function() { $('#complete-bonfire-dialog').modal('show'); // Only post to server if there is an authenticated user if ($('.signup-btn-nav').length < 1) { - $.ajax({ - type: 'POST', - data: { + + $.post( + '/completed-bonfire', + { bonfireInfo: { completedWith : didCompleteWith, solution: bonfireSolution, bonfireHash: thisBonfireHash } }, - url: '/completed-bonfire/' - - }); + function(res) { + if (res) { + window.location.href = 'http://localhost:3001/bonfires' + } + }) } } + $('.next-bonfire-button').on('click', function() { + var bonfireSolution = myCodeMirror.getValue(); + var thisBonfireHash = passedBonfireHash || null; + var didCompleteWith = $('#completed-with').val() || null; + + completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash); + + }); + $('.all-challenges').on('click', function() { $('#all-challenges-dialog').modal('show'); }); @@ -68,19 +80,6 @@ $(document).ready(function() { }); - $('.next-bonfire-button').on('click', function() { - var bonfireSolution = myCodeMirror.getValue(); - var thisBonfireHash = passedBonfireHash || null; - var didCompleteWith = $('#completed-with').val() || null; - - completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash); - - window.setTimeout(function() { - // TODO - window.location = '/bonfires'; - }, 100); - - }); // Bonfire instructions functions $('#more-info').on('click', function() {