From 07ba7e4fcbb6b77742200a6efbb8fee939b08990 Mon Sep 17 00:00:00 2001 From: Michael Q Larson Date: Thu, 4 Dec 2014 12:06:17 -0800 Subject: [PATCH] continue work on challengeshash --- app.js | 6 +++--- config/passport.js | 8 ++++---- controllers/challenges.js | 3 ++- controllers/home.js | 1 - views/partials/navbar.jade | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index 5fcd7d7c3c..0c7ab23611 100644 --- a/app.js +++ b/app.js @@ -165,20 +165,20 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink); * API examples routes. */ app.post('/completed_challenge', function(req, res) { - console.log(req.user); req.user.challengesHash[parseInt(req.body.cn)] = Math.round(+new Date() / 1000); req.user.challengesCompleted = function() { var completed = []; + var h = req.user.challengesHash; for (i = 0; i < h.length; i++) { + console.log(h[i] > 0) if (h[i] > 0) { + console.log(h[i]); completed.push(i); } return completed; } } req.user.save(); - console.log(req.user.challengesHash); - console.log(req.user.challengesCompleted); }); /** diff --git a/config/passport.js b/config/passport.js index 517462d41c..18816ac4e9 100644 --- a/config/passport.js +++ b/config/passport.js @@ -77,10 +77,10 @@ passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tok user.save(function(err) { done(err, user); }); - if (!user.email) { - res.redirect('/account'); - req.flash('errors', { msg: 'OK, you are signed in. Please add your email address to your profile.' }); - } + //if (!user.email) { + // res.redirect('/account'); + // req.flash('errors', { msg: 'OK, you are signed in. Please add your email address to your profile.' }); + //} }); } })); diff --git a/controllers/challenges.js b/controllers/challenges.js index e7f951f0cc..9d0b30291d 100644 --- a/controllers/challenges.js +++ b/controllers/challenges.js @@ -19,7 +19,8 @@ exports.returnChallenge = function(req, res, next) { video: c.video, time: c.time, steps: c.steps, - cc: req.user.challengesHash + cc: req.user.challengesCompleted, + ch: req.user.challengesHash }); }); }; \ No newline at end of file diff --git a/controllers/home.js b/controllers/home.js index b29d5ac698..df6ff23c8c 100644 --- a/controllers/home.js +++ b/controllers/home.js @@ -6,7 +6,6 @@ exports.index = function(req, res) { if (req.user) { if (req.user.challengesCompleted.length > 0) { - Object.values(req.user.challengesHash); nextChallenge = Math.max.apply(Math, req.user.challengesHash) + 1; res.redirect("challenges/" + nextChallenge); } else { diff --git a/views/partials/navbar.jade b/views/partials/navbar.jade index 486ad6d731..f27bf1d06f 100644 --- a/views/partials/navbar.jade +++ b/views/partials/navbar.jade @@ -20,7 +20,7 @@ img(src='#{user.profile.picture}') else img(src='#{user.gravatar(60)}') - | #{user.profile.name || user.email || user.id} [ #{user.completedChallengeCount)} ]  + | #{user.profile.name || user.email || user.id} [ #{user.challengesCompleted.length} ]  i.caret ul.dropdown-menu li