Changed from post to put for since updating not creatings
This commit is contained in:
2
app.js
2
app.js
@ -470,7 +470,7 @@ app.post(
|
|||||||
storyController.commentOnCommentSubmit
|
storyController.commentOnCommentSubmit
|
||||||
);
|
);
|
||||||
|
|
||||||
app.post(
|
app.put(
|
||||||
'/stories/comment/:id/edit',
|
'/stories/comment/:id/edit',
|
||||||
storyController.commentEdit
|
storyController.commentEdit
|
||||||
);
|
);
|
||||||
|
@ -424,16 +424,18 @@ exports.commentOnCommentSubmit = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.commentEdit = function(req, res, next){
|
exports.commentEdit = function(req, res, next){
|
||||||
if (req.user._id.toString() !== req.body.data.author.userId.toString()) {
|
//console.log(JSON.stringify(req));
|
||||||
|
console.log(JSON.stringify(req.body));
|
||||||
|
if (req.user._id.toString() !== req.body.author.userId.toString()) {
|
||||||
return next(new Error('Not authorized'));
|
return next(new Error('Not authorized'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = req.params.id;
|
var data = req.params.id;
|
||||||
var sanitizedBody = sanitizeHtml(req.body.data.body,{
|
var sanitizedBody = sanitizeHtml(req.body.body,{
|
||||||
allowedTags: [],
|
allowedTags: [],
|
||||||
allowedAttributes: []
|
allowedAttributes: []
|
||||||
}).replace(/"/g, '"');
|
}).replace(/"/g, '"');
|
||||||
if (req.body.data.body !== sanitizedBody) {
|
if (req.body.body !== sanitizedBody) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: 'HTML is not allowed'
|
msg: 'HTML is not allowed'
|
||||||
});
|
});
|
||||||
|
@ -129,8 +129,10 @@
|
|||||||
var submitCommentForEditToCommentHandler = function submitCommentForEditToCommentHandler() {
|
var submitCommentForEditToCommentHandler = function submitCommentForEditToCommentHandler() {
|
||||||
$('#submit-comment-to-edit').unbind('click');
|
$('#submit-comment-to-edit').unbind('click');
|
||||||
console.log('in comments.jade', originalStoryAuthorEmail);
|
console.log('in comments.jade', originalStoryAuthorEmail);
|
||||||
$.post('/stories/comment/' + commentId + '/edit',
|
|
||||||
{
|
$.ajax({
|
||||||
|
type: "PUT",
|
||||||
|
url: '/stories/comment/' + commentId + '/edit',
|
||||||
data: {
|
data: {
|
||||||
associatedPost: commentId,
|
associatedPost: commentId,
|
||||||
originalStoryLink: originalStoryLink,
|
originalStoryLink: originalStoryLink,
|
||||||
@ -142,15 +144,15 @@
|
|||||||
username: user.profile.username,
|
username: user.profile.username,
|
||||||
email: user.email
|
email: user.email
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
success: function (msg) {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
error: function (err){
|
||||||
|
$('#submit-comment-to-edit').bind('click', submitCommentForEditToCommentHandler);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.fail(function (xhr, textStatus, errorThrown) {
|
|
||||||
$('#submit-comment-to-edit').bind('click', submitCommentForEditToCommentHandler);
|
|
||||||
})
|
|
||||||
.done(function (data, textStatus, xhr) {
|
|
||||||
window.location.reload();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#submit-comment-to-edit').on('click', submitCommentForEditToCommentHandler)
|
$('#submit-comment-to-edit').on('click', submitCommentForEditToCommentHandler)
|
||||||
|
Reference in New Issue
Block a user