diff --git a/controllers/story.js b/controllers/story.js index be129b8dd1..a76fd6e820 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -148,7 +148,7 @@ exports.returnIndividualStory = function(req, res, next) { upVotes: story.upVotes, comments: story.comments, id: story._id, - user: req.user, + user: req.user || null, timeAgo: moment(story.timePosted).fromNow(), image: story.image, page: 'show', @@ -227,6 +227,9 @@ exports.comments = function(req, res, next) { }; exports.newStory = function(req, res) { + if (!req.user) { + return res.status(500); + } var url = req.body.data.url; var cleanURL = sanitizeHtml(url, { allowedTags: [], @@ -284,6 +287,9 @@ exports.newStory = function(req, res) { exports.storySubmission = function(req, res) { var data = req.body.data; + if (req.user._id.toString() !== data.author.userId.toString()) { + return res.status(500); + } var storyLink = data.headline .replace(/\'/g, '') .replace(/\"/g, '') @@ -327,6 +333,9 @@ exports.storySubmission = function(req, res) { exports.commentSubmit = function(req, res) { var data = req.body.data; + if (req.user._id.toString() !== data.author.userId.toString()) { + return res.status(500); + } var sanitizedBody = sanitizeHtml(data.body, { allowedTags: [], @@ -353,6 +362,11 @@ exports.commentSubmit = function(req, res) { exports.commentOnCommentSubmit = function(req, res) { var data = req.body.data; + + if (req.user._id.toString() !== data.author.userId.toString()) { + return res.status(500); + } + var sanitizedBody = sanitizeHtml(data.body, { allowedTags: [], diff --git a/controllers/user.js b/controllers/user.js index 25a02d63a7..7648e80441 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -322,7 +322,6 @@ exports.updateProgress = function(req, res) { exports.postUpdateProfile = function(req, res, next) { - // What does this do? User.findById(req.user.id, function(err, user) { if (err) return next(err); var errors = req.validationErrors(); @@ -342,7 +341,7 @@ exports.postUpdateProfile = function(req, res, next) { }); return res.redirect('/account'); } - User.findOne({ username: req.body.username }, function(err, existingUsername) { + User.findOne({ 'profile.username': req.body.username }, function(err, existingUsername) { if (err) { return next(err); } diff --git a/public/js/lib/bonfire/bonfireFramework_v0.1.2.js b/public/js/lib/bonfire/bonfireFramework_v0.1.2.js index a4ae597c07..7721ece9f2 100644 --- a/public/js/lib/bonfire/bonfireFramework_v0.1.2.js +++ b/public/js/lib/bonfire/bonfireFramework_v0.1.2.js @@ -33,6 +33,9 @@ editor.setOption("extraKeys", { cm.replaceSelection(spaces); } }, + + + "Ctrl-Enter": function() { bonfireExecute(); return false; diff --git a/views/stories/comments.jade b/views/stories/comments.jade index 53ae1f12b3..751f65f915 100644 --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -21,6 +21,7 @@ success: function (data, textStatus, xhr) { commentDetails = data; var div = document.createElement('div'); + $(div) .html( '
' + @@ -55,6 +56,9 @@ sentinel--; if (!sentinel) { $('.comment-a-comment').on('click', 'a', function () { + if (!user) { + return; + } $(this).unbind('click'); $('.comment-to-comment-formgroup').empty(); $('#initial-comment-submit').addClass('hidden-element'); diff --git a/views/stories/show.jade b/views/stories/show.jade index 833ef94bcb..52e049b5f9 100644 --- a/views/stories/show.jade +++ b/views/stories/show.jade @@ -42,22 +42,23 @@ span  by  a(href="/" + author.username) @#{author.username} - - .col-xs-12#reply-area - .hidden-element#initial-comment-submit - form.form-horizontal.control-label-story-submission - .col-xs-12 - .input-group - input#comment-box.big-text-field.field-responsive.form-control(type='text', placeholder='Enter your reply', autofocus) - span.input-group-btn - button#comment-button.btn.btn-big.btn-primary.btn-responsive(type='button') Send - span.spacer.pull-left#textarea_feedback + if (user !== null) + .col-xs-12#reply-area + .hidden-element#initial-comment-submit + form.form-horizontal.control-label-story-submission + .col-xs-12 + .input-group + input#comment-box.big-text-field.field-responsive.form-control(type='text', placeholder='Enter your reply', autofocus) + span.input-group-btn + button#comment-button.btn.btn-big.btn-primary.btn-responsive(type='button') Send + span.spacer.pull-left#textarea_feedback script. if (image) { $('#image-display').removeClass('hidden-element') } $('#reply-to-main-post').on('click', function() { + if (!user) return; $('#initial-comment-submit').removeClass('hidden-element'); $(this).unbind('click'); $('.comment-to-comment-formgroup').empty();