Loading comments/api_adapter.js +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ module.exports = { */ commentToJson: function(comment) { return { _id: comment.id, author: comment.username, contentHtml: comment.content_html, createdAt: String(comment.created_at), Loading comments/app.js +17 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,23 @@ app.get('/auth/:sdk/:version/comments', services.comments, function(req, res) { }); }); // Adds new comment app.post('/auth/:sdk/:version/comments', services.requireLogin, services.comments, function(req, res) { var comment = { user_id: req.session.user.id, target: ApiAdapter.targetFromJson(JSON.parse(req.body.target)), content: req.body.comment }; req.comments.add(comment, function(err, comment_id) { res.json({ id: comment_id, success: true }); }); }); // Returns all subscriptions for logged in user // For now does nothing. app.get('/auth/:sdk/:version/subscriptions', function(req, res) { Loading comments/services.js +12 −0 Original line number Diff line number Diff line Loading @@ -25,5 +25,17 @@ module.exports = { var forumAuth = new ForumAuth(new DbFacade(config.forumDb)); req.users = new Users(new DbFacade(config.mysql), forumAuth); next(); }, /** * Requires that user is logged in. */ requireLogin: function(req, res, next) { if (!req.session || !req.session.user) { res.json({success: false, reason: 'Forbidden'}, 403); } else { next(); } } }; Loading
comments/api_adapter.js +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ module.exports = { */ commentToJson: function(comment) { return { _id: comment.id, author: comment.username, contentHtml: comment.content_html, createdAt: String(comment.created_at), Loading
comments/app.js +17 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,23 @@ app.get('/auth/:sdk/:version/comments', services.comments, function(req, res) { }); }); // Adds new comment app.post('/auth/:sdk/:version/comments', services.requireLogin, services.comments, function(req, res) { var comment = { user_id: req.session.user.id, target: ApiAdapter.targetFromJson(JSON.parse(req.body.target)), content: req.body.comment }; req.comments.add(comment, function(err, comment_id) { res.json({ id: comment_id, success: true }); }); }); // Returns all subscriptions for logged in user // For now does nothing. app.get('/auth/:sdk/:version/subscriptions', function(req, res) { Loading
comments/services.js +12 −0 Original line number Diff line number Diff line Loading @@ -25,5 +25,17 @@ module.exports = { var forumAuth = new ForumAuth(new DbFacade(config.forumDb)); req.users = new Users(new DbFacade(config.mysql), forumAuth); next(); }, /** * Requires that user is logged in. */ requireLogin: function(req, res, next) { if (!req.session || !req.session.user) { res.json({success: false, reason: 'Forbidden'}, 403); } else { next(); } } };