Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ function isLoggedIn(req, res, next) {

// if they aren't redirect them to the home page
res.redirect('/');
}
}
25 changes: 9 additions & 16 deletions controllers/posts/detailPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ module.exports = {

var id = req.params["id"];

if ( ! req.session.user) {
var error = {
code: 300,
message: "please login"
}
return res.render('index.jade', { title: 'Xgag', error: error});
}

if (! id) {
return res.json({
code: 500,
Expand All @@ -57,21 +49,22 @@ module.exports = {
});
},
addcomment: function(req, res){

if ( ! req.session.user) {
return res.json({
code: 300,
message: "please login"
});
}

var date = new Date();
var id = req.params["id"].replace(/id=/g, "");
console.log(req.session.user);
var newComment = new models.comment;

var newComment = new models.comment;
newComment.user = req.session.user.id;
newComment.create_date = date;
newComment.message = req.body.message;
newComment.status = req.body.status;
if ( ! req.session.user || typeof req.session.user==undefined) {
return res.json({
code: 300,
message: "please login"
});
}

if (! id) {
return res.json({
Expand Down
3 changes: 3 additions & 0 deletions public/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ $(function(){
message: message,
status: status
}, function (result) {
if(result.code != 200){
return alert(result.message);
}
// clean input
node.find('input[name=comment]').val('');
$("#"+postId+" > div.comment-box > div.comment-area").text('');
Expand Down
18 changes: 11 additions & 7 deletions views/postDetail.jade
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ block content
i.fa.fa-thumbs-o-down
span.dislike #{posts.dislike.length}
.comment-box
.comment-area
.comment-body
form.comment-form(action="/comment/add/#{posts._id}" role="form")
.form-group
input(type="text" class="form-control" name="comment" placeholder="評論..." value="")
input(type="hidden" name="status" value="")
input(type="hidden" name="post_id" value="#{posts._id}")
.comment-area
if !user
.content-text
|留言請登入
else
.comment-body
form.comment-form(action="/comment/add/#{posts._id}" role="form")
.form-group
input(type="text" class="form-control" name="comment" placeholder="評論..." value="")
input(type="hidden" name="status" value="")
input(type="hidden" name="post_id" value="#{posts._id}")


.col-md-4(style="margin-top: 80px;")
Expand Down