fix unauthenticated challenge bug and hide pair, bug and help buttons when unauthenticated

This commit is contained in:
Quincy Larson
2015-05-25 18:00:45 -07:00
parent 95ab51986e
commit 08837304fd
5 changed files with 60 additions and 51 deletions

View File

@@ -175,20 +175,22 @@ exports.returnIndividualChallenge = function(req, res, next) {
if (dashedNameFull !== dashedName) {
return res.redirect('../challenges/' + dashedNameFull);
} else {
req.user.currentChallenge = {
challengeId: challenge._id,
challengeName: challenge.name,
challengeBlock: R.head(R.flatten(Object.keys(challengeMapWithIds).
map(function(key) {
return challengeMapWithIds[key]
.filter(function(elem) {
return String(elem) === String(challenge._id);
}).map(function() {
return key;
});
})
))
};
if (req.user) {
req.user.currentChallenge = {
challengeId: challenge._id,
challengeName: challenge.name,
challengeBlock: R.head(R.flatten(Object.keys(challengeMapWithIds).
map(function (key) {
return challengeMapWithIds[key]
.filter(function (elem) {
return String(elem) === String(challenge._id);
}).map(function () {
return key;
});
})
))
};
}
}
var challengeType = {
@@ -295,12 +297,16 @@ exports.returnIndividualChallenge = function(req, res, next) {
});
}
};
req.user.save(function(err) {
if (err) {
return next(err);
}
if (req.user) {
req.user.save(function (err) {
if (err) {
return next(err);
}
return challengeType[challenge.challengeType]();
});
} else {
return challengeType[challenge.challengeType]();
});
}
});
};