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

View File

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

View File

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

View File

@ -36,17 +36,18 @@ block content
| Less information | Less information
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
.button-spacer .button-spacer
.btn-group.input-group.btn-group-justified if (user)
label.btn.btn-success#i-want-help .btn-group.input-group.btn-group-justified
i.fa.fa-medkit label.btn.btn-success#i-want-help
|   Help i.fa.fa-medkit
label.btn.btn-success#i-want-to-pair |   Help
i.fa.fa-user-plus label.btn.btn-success#i-want-to-pair
|   Pair i.fa.fa-user-plus
label.btn.btn-success#report-issue |   Pair
i.fa.fa-bug label.btn.btn-success#report-issue
|   Bug i.fa.fa-bug
br |   Bug
.spacer
form.code form.code
.form-group.codeMirrorView .form-group.codeMirrorView
textarea#codeOutput(style='display: none;') 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) a.btn.btn-primary.btn-big.btn-block#completed-courseware I've completed this challenge (ctrl + enter)
script. script.
var userLoggedIn = true; 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 - else
a.btn.btn-big.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.btn.btn-big.signup-btn.btn-block(href='/login') Sign in so you can save your progress
script. script.
var userLoggedIn = false; var userLoggedIn = false;
br 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"). script(type="text/javascript").
var controlEnterHandler = function(e) { var controlEnterHandler = function(e) {