From c13bdb65e51b111749aad440fc3c12a6472ae1b1 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 6 Oct 2015 23:23:44 -0700 Subject: [PATCH 1/3] Add camper must be auth with gitub to post to news --- server/boot/story.js | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/server/boot/story.js b/server/boot/story.js index d46b79f079..6e1ca30202 100755 --- a/server/boot/story.js +++ b/server/boot/story.js @@ -12,13 +12,18 @@ var Rx = require('rx'), validator = require('validator'), secrets = require('../../config/secrets'); -var foundationDate = 1413298800000; -var time48Hours = 172800000; +import { + ifNoUser401, + ifNoUserRedirectTo +} from '../utils/middleware'; -var unDasherize = utils.unDasherize; -var dasherize = utils.dasherize; -var getURLTitle = utils.getURLTitle; -var ifNoUser401 = require('../utils/middleware').ifNoUser401; +const foundationDate = 1413298800000; +const time48Hours = 172800000; + +const unDasherize = utils.unDasherize; +const dasherize = utils.dasherize; +const getURLTitle = utils.getURLTitle; +const sendNonUserToNews = ifNoUserRedirectTo('/news'); function hotRank(timeValue, rank) { /* @@ -62,8 +67,16 @@ module.exports = function(app) { router.get('/news/hot', hotJSON); router.get('/stories/hotStories', hotJSON); - router.get('/stories/submit', submitNew); - router.get('/stories/submit/new-story', preSubmit); + router.get( + '/stories/submit', + sendNonUserToNews, + submitNew + ); + router.get( + '/stories/submit/new-story', + sendNonUserToNews, + preSubmit + ); router.post('/stories/preliminary', ifNoUser401, newStory); router.post('/stories/', ifNoUser401, storySubmission); router.get('/news/', hot); @@ -102,17 +115,24 @@ module.exports = function(app) { } function submitNew(req, res) { + if (!req.user.isGithubCool) { + req.flash('errors', { + msg: 'You must authenticate with Github to post to Camper News' + }); + return res.redirect('/news'); + } + return res.render('stories/index', { title: 'Submit a new story to Camper News', page: 'submit' }); } - function preSubmit(req, res, next) { + function preSubmit(req, res) { var data = req.query; if (typeof data.url !== 'string') { req.flash('errors', { msg: 'No URL supplied with story' }); - return next(new TypeError('No URL supplied with story')); + return res.redirect('/news'); } var cleanedData = cleanData(data.url); @@ -264,8 +284,11 @@ module.exports = function(app) { } function newStory(req, res, next) { - if (!req.user) { - return next(new Error('Must be logged in')); + if (!req.user.isGithubCool) { + req.flash('errors', { + msg: 'You must authenticate with Github to post to Camper News' + }); + return res.redirect('/news'); } var url = req.body.data.url; From 49101183663ffca913880f507a3071bdb4e86339 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Fri, 23 Oct 2015 14:12:09 -0700 Subject: [PATCH 2/3] update flash message --- server/boot/story.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/boot/story.js b/server/boot/story.js index 6e1ca30202..c1f188db81 100755 --- a/server/boot/story.js +++ b/server/boot/story.js @@ -117,7 +117,8 @@ module.exports = function(app) { function submitNew(req, res) { if (!req.user.isGithubCool) { req.flash('errors', { - msg: 'You must authenticate with Github to post to Camper News' + msg: 'You must link GitHub with your account before you can post' + + ' on Camper News.' }); return res.redirect('/news'); } From 2ac70458b0016abfca1c3603a42c9c9fc6b50162 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Fri, 23 Oct 2015 14:28:27 -0700 Subject: [PATCH 3/3] remove unnecessary bullet point from Camper News view --- server/views/stories/hot-stories.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/views/stories/hot-stories.jade b/server/views/stories/hot-stories.jade index 8cc7bb7659..9d512f8a8b 100644 --- a/server/views/stories/hot-stories.jade +++ b/server/views/stories/hot-stories.jade @@ -69,7 +69,7 @@ (typeof username !== 'undefined' ? "" : "upvote") + - " · " + + "   " + rank + (rank > 1 ? " points" : " point") + " · posted " + moment(data[i].timePosted).fromNow() + " by @" + data[i].author.username + " " +