From 92f4c7a41a3896b2b91356cc959d1de54a70f565 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Thu, 21 May 2015 09:15:16 -0700 Subject: [PATCH 1/3] Use findone in controllers/story also fixes some linting issues closes #469 --- controllers/story.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index cfde5345ef..bddc71736b 100755 --- a/controllers/story.js +++ b/controllers/story.js @@ -128,7 +128,8 @@ exports.returnIndividualStory = function(req, res, next) { if (story.length < 1) { req.flash('errors', { - msg: "404: We couldn't find a story with that name. Please double check the name." + msg: "404: We couldn't find a story with that name. " + + "Please double check the name." }); return res.redirect('/news/'); @@ -229,12 +230,10 @@ exports.upvote = function(req, res, next) { ); story.markModified('rank'); story.save(); - User.find({'_id': story.author.userId}, function(err, user) { - 'use strict'; + User.findOne({'_id': story.author.userId}, function(err, user) { if (err) { return next(err); } - user = user.pop(); user.progressTimestamps.push(Date.now() || 0); user.save(function (err, user) { req.user.save(function (err, user) { @@ -339,7 +338,7 @@ exports.storySubmission = function(req, res, next) { if (link.search(/^https?:\/\//g) === -1) { link = 'http://' + link; } - Story.count({'storyLink': new RegExp('^' + storyLink + '(?: [0-9]+)?$', 'i')}, function (err, storyCount) { + Story.count({ storyLink: new RegExp('^' + storyLink + '(?: [0-9]+)?$', 'i')}, function (err, storyCount) { if (err) { return res.status(500); } @@ -513,7 +512,8 @@ exports.storySubmission = function(req, res, next) { return next(err); } try { - // Based on the context retrieve the parent object of the comment (Story/Comment) + // Based on the context retrieve the parent + // object of the comment (Story/Comment) Context.find({'_id': data.associatedPost}, function (err, associatedContext) { if (err) { return next(err); @@ -533,8 +533,15 @@ exports.storySubmission = function(req, res, next) { if (err) { return next(err); } - // If the emails of both authors differ, only then proceed with email notification - if (typeof data.author !== 'undefined' && data.author.email && typeof recipient !== 'undefined' && recipient.email && (data.author.email !== recipient.email)) { + // If the emails of both authors differ, + // only then proceed with email notification + if ( + typeof data.author !== 'undefined' && + data.author.email && + typeof recipient !== 'undefined' && + recipient.email && + (data.author.email !== recipient.email) + ) { var transporter = nodemailer.createTransport({ service: 'Mandrill', auth: { @@ -546,11 +553,16 @@ exports.storySubmission = function(req, res, next) { var mailOptions = { to: recipient.email, from: 'Team@freecodecamp.com', - subject: data.author.username + ' replied to your post on Camper News', + subject: data.author.username + + ' replied to your post on Camper News', text: [ - 'Just a quick heads-up: ' + data.author.username + ' replied to you on Camper News.', + 'Just a quick heads-up: ', + data.author.username, + ' replied to you on Camper News.', 'You can keep this conversation going.', - 'Just head back to the discussion here: http://freecodecamp.com/news/' + data.originalStoryLink, + 'Just head back to the discussion here: ', + 'http://freecodecamp.com/news/', + data.originalStoryLink, '- the Free Code Camp Volunteer Team' ].join('\n') }; From 96556a4a87295f52eb9d3e0d525fdbb76190dee4 Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Fri, 22 May 2015 08:34:28 -0400 Subject: [PATCH 2/3] Fix email-signin redirect when logging in from camper news --- controllers/user.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/user.js b/controllers/user.js index ae434c4a22..cd961db05a 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -53,6 +53,9 @@ exports.postSignin = function(req, res, next) { return next(err); } req.flash('success', { msg: 'Success! You are logged in.' }); + if (/hotStories/.test(req.session.returnTo)) { + return res.redirect('../news'); + } return res.redirect(req.session.returnTo || '/'); }); })(req, res, next); From fd8a291ecd4c7a1137c8062225ca98d2577190f5 Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Fri, 22 May 2015 08:39:03 -0400 Subject: [PATCH 3/3] Fix import of constantStrings.json in resources controller --- controllers/resources.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/resources.js b/controllers/resources.js index 9f80434b59..1f0235697f 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -9,7 +9,7 @@ var async = require('async'), _ = require('lodash'), fs = require('fs'), - constantStrings = require('constantStrings.json'), + constantStrings = require('./constantStrings.json'), User = require('../models/User'), Challenge = require('./../models/Challenge'), Story = require('./../models/Story'),