Merge pull request #3849 from FreeCodeCamp/feature/block-camper-news

Add camper must be auth with gitub to post to news
This commit is contained in:
Quincy Larson
2015-10-23 14:28:47 -07:00
2 changed files with 37 additions and 13 deletions

View File

@ -12,13 +12,18 @@ var Rx = require('rx'),
validator = require('validator'), validator = require('validator'),
secrets = require('../../config/secrets'); secrets = require('../../config/secrets');
var foundationDate = 1413298800000; import {
var time48Hours = 172800000; ifNoUser401,
ifNoUserRedirectTo
} from '../utils/middleware';
var unDasherize = utils.unDasherize; const foundationDate = 1413298800000;
var dasherize = utils.dasherize; const time48Hours = 172800000;
var getURLTitle = utils.getURLTitle;
var ifNoUser401 = require('../utils/middleware').ifNoUser401; const unDasherize = utils.unDasherize;
const dasherize = utils.dasherize;
const getURLTitle = utils.getURLTitle;
const sendNonUserToNews = ifNoUserRedirectTo('/news');
function hotRank(timeValue, rank) { function hotRank(timeValue, rank) {
/* /*
@ -62,8 +67,16 @@ module.exports = function(app) {
router.get('/news/hot', hotJSON); router.get('/news/hot', hotJSON);
router.get('/stories/hotStories', hotJSON); router.get('/stories/hotStories', hotJSON);
router.get('/stories/submit', submitNew); router.get(
router.get('/stories/submit/new-story', preSubmit); '/stories/submit',
sendNonUserToNews,
submitNew
);
router.get(
'/stories/submit/new-story',
sendNonUserToNews,
preSubmit
);
router.post('/stories/preliminary', ifNoUser401, newStory); router.post('/stories/preliminary', ifNoUser401, newStory);
router.post('/stories/', ifNoUser401, storySubmission); router.post('/stories/', ifNoUser401, storySubmission);
router.get('/news/', hot); router.get('/news/', hot);
@ -102,17 +115,25 @@ module.exports = function(app) {
} }
function submitNew(req, res) { function submitNew(req, res) {
if (!req.user.isGithubCool) {
req.flash('errors', {
msg: 'You must link GitHub with your account before you can post' +
' on Camper News.'
});
return res.redirect('/news');
}
return res.render('stories/index', { return res.render('stories/index', {
title: 'Submit a new story to Camper News', title: 'Submit a new story to Camper News',
page: 'submit' page: 'submit'
}); });
} }
function preSubmit(req, res, next) { function preSubmit(req, res) {
var data = req.query; var data = req.query;
if (typeof data.url !== 'string') { if (typeof data.url !== 'string') {
req.flash('errors', { msg: 'No URL supplied with story' }); 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); var cleanedData = cleanData(data.url);
@ -264,8 +285,11 @@ module.exports = function(app) {
} }
function newStory(req, res, next) { function newStory(req, res, next) {
if (!req.user) { if (!req.user.isGithubCool) {
return next(new Error('Must be logged in')); req.flash('errors', {
msg: 'You must authenticate with Github to post to Camper News'
});
return res.redirect('/news');
} }
var url = req.body.data.url; var url = req.body.data.url;

View File

@ -69,7 +69,7 @@
(typeof username !== 'undefined' ? (typeof username !== 'undefined' ?
"<button id='" + data[i].id + "' class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost btn-upvote'>upvote</button>" : "<button id='" + data[i].id + "' class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost btn-upvote'>upvote</button>" :
"<a href='/signin' class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost'>upvote</a>") + "<a href='/signin' class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost'>upvote</a>") +
"<a class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost hidden' href='/news/" + linkedName + "'>more info</a> · " + "<a class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost hidden' href='/news/" + linkedName + "'>more info</a> &nbsp; " +
rank + (rank > 1 ? " points" : " point") + " · posted " + rank + (rank > 1 ? " points" : " point") + " · posted " +
moment(data[i].timePosted).fromNow() + moment(data[i].timePosted).fromNow() +
" by <a href='/" + data[i].author.username + "'>@" + data[i].author.username + "</a> " + " by <a href='/" + data[i].author.username + "'>@" + data[i].author.username + "</a> " +