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]();
});
}
});
};

View File

@ -91,17 +91,18 @@ block content
span.ion-close-circled
| Username not found
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
.button-spacer
.btn-group.input-group.btn-group-justified
label.btn.btn-success#i-want-help
i.fa.fa-medkit
|   Help
label.btn.btn-success#i-want-to-pair
i.fa.fa-user-plus
|   Pair
label.btn.btn-success#report-issue
i.fa.fa-bug
|   Bug
if (user)
.button-spacer
.btn-group.input-group.btn-group-justified
label.btn.btn-success#i-want-help
i.fa.fa-medkit
|   Help
label.btn.btn-success#i-want-to-pair
i.fa.fa-user-plus
|   Pair
label.btn.btn-success#report-issue
i.fa.fa-bug
|   Bug
.button-spacer
form.code
.form-group.codeMirrorView

View File

@ -37,8 +37,8 @@ block content
#less-info.btn.btn-primary.btn-block.btn-primary-ghost
span.ion-arrow-up-b
| Less information
br
- if (user)
br
a.btn.btn-primary.btn-big.btn-block#next-courseware-button
| Go to my next challenge
br

View File

@ -36,17 +36,18 @@ block content
| Less information
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
.button-spacer
.btn-group.input-group.btn-group-justified
label.btn.btn-success#i-want-help
i.fa.fa-medkit
|   Help
label.btn.btn-success#i-want-to-pair
i.fa.fa-user-plus
|   Pair
label.btn.btn-success#report-issue
i.fa.fa-bug
|   Bug
br
if (user)
.btn-group.input-group.btn-group-justified
label.btn.btn-success#i-want-help
i.fa.fa-medkit
|   Help
label.btn.btn-success#i-want-to-pair
i.fa.fa-user-plus
|   Pair
label.btn.btn-success#report-issue
i.fa.fa-bug
|   Bug
.spacer
form.code
.form-group.codeMirrorView
textarea#codeOutput(style='display: none;')

View File

@ -21,20 +21,21 @@ block content
a.btn.btn-primary.btn-big.btn-block#completed-courseware I've completed this challenge (ctrl + enter)
script.
var userLoggedIn = true;
.button-spacer
.btn-group.input-group.btn-group-justified
.btn.btn-success.btn-big#i-want-help-editorless
i.fa.fa-medkit
|   Get help
.btn.btn-success.btn-big#report-issue
i.fa.fa-bug
|   Report a bug
.button-spacer
- else
a.btn.btn-big.signup-btn.btn-block(href='/login') Sign in so you can save your progress
script.
var userLoggedIn = false;
br
.button-spacer
.btn-group.input-group.btn-group-justified
.btn.btn-success.btn-big#i-want-help-editorless
i.fa.fa-medkit
|   Get help
.btn.btn-success.btn-big#report-issue
i.fa.fa-bug
|   Report a bug
.button-spacer
script(type="text/javascript").
var controlEnterHandler = function(e) {