diff options
Diffstat (limited to 'bucky')
| -rw-r--r-- | bucky/app/bucky.js | 31 | ||||
| -rw-r--r-- | bucky/app/index.js | 16 | ||||
| -rw-r--r-- | bucky/app/router.js | 4 | ||||
| -rw-r--r-- | bucky/util/auth.js | 2 |
4 files changed, 43 insertions, 10 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 8b829da..e7455ad 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -94,7 +94,7 @@ var bucky = module.exports = { next() }) }, - + /* DETAILS */ ensureThread: function (req, res, next){ @@ -112,6 +112,24 @@ var bucky = module.exports = { } }) }, + ensureCommentThread: function (req, res, next){ + if (! res.comment) { + return res.sendStatus(404) + } + var id = res.comment.get('thread') + if (! id) { + return res.sendStatus(404) + } + db.getThread(id).then(function(thread){ + if (thread) { + res.thread = thread + next() + } + else { + res.sendStatus(404) + } + }) + }, ensureKeywordForThread: function (req, res, next){ var keyword = res.thread.get('keyword') if (! keyword) return next() @@ -132,7 +150,16 @@ var bucky = module.exports = { next() }) }, - + bumpViewCount: function(req, res, next) { + res.thread.set('viewed', res.thread.get('viewed') + 1) + res.thread.save().then( () => next() ) + }, + bumpThreadRevisions: function (req, res, next){ + res.thread.set('revision', res.thread.get('revision')+1) + res.thread.set('lastmodified', util.now()) + res.thread.save().then( () => next() ) + }, + /* KEYWORDS */ ensureKeyword: function (req, res, next){ diff --git a/bucky/app/index.js b/bucky/app/index.js index 0da18c7..85c1d82 100644 --- a/bucky/app/index.js +++ b/bucky/app/index.js @@ -13,6 +13,7 @@ var favicon = require('serve-favicon') var passport = require('passport') var sessionstore = require('sessionstore') var session = require('express-session') +var MongoStore = require('connect-mongo')(session); var upload = require('../util/upload') var app, server @@ -28,13 +29,14 @@ site.init = function(){ key: 'bucky.sid', secret: 'argonauts', cookie: { domain: '.' + process.env.HOST_NAME, maxAge: 43200000000 }, - store: sessionstore.createSessionStore({ - type: 'mongodb', - host: 'localhost', - port: 27017, - dbName: 'buckySessionDb', - collectionName: 'sessions', - timeout: 10000, + store: new MongoStore({ + url: 'mongodb://localhost/buckySessionDb' +// type: 'mongodb', +// host: 'localhost', +// port: 27017, +// dbName: 'buckySessionDb', +// collectionName: 'sessions', +// timeout: 10000, }), resave: true, saveUninitialized: false, diff --git a/bucky/app/router.js b/bucky/app/router.js index 8ff9d87..ac176bc 100644 --- a/bucky/app/router.js +++ b/bucky/app/router.js @@ -85,6 +85,7 @@ module.exports = function(app){ bucky.ensureKeywordForThread, bucky.ensureCommentsForThread, bucky.ensureFilesForThread, + bucky.bumpViewCount, function(req, res){ res.json({ thread: res.thread, @@ -111,6 +112,7 @@ module.exports = function(app){ bucky.verifyFilesOrComment, bucky.createOptionalFiles, bucky.createOptionalComment, + bucky.bumpThreadRevisions, function(req, res){ res.json({ comment: res.comment @@ -127,7 +129,9 @@ module.exports = function(app){ middleware.ensureAuthenticated, bucky.ensureComment, bucky.checkCommentPrivacy, + bucky.ensureCommentThread, bucky.updateComment, + bucky.bumpThreadRevisions, function(req, res){ res.json({ comment: res.comment }) }) diff --git a/bucky/util/auth.js b/bucky/util/auth.js index 6fdd5bd..41cd155 100644 --- a/bucky/util/auth.js +++ b/bucky/util/auth.js @@ -33,7 +33,7 @@ var auth = module.exports = { if (req.isAuthenticated()) { var returnTo = req.session.returnTo delete req.session.returnTo - console.log("LOGGED IN", req.user.username) + console.log(">> logged in", req.user.get('username')) return res.json({ status: "OK", user: auth.sanitizeUser(req.user), |
