Merge pull request #473 from terakilobyte/staging
E-mail signin from camper news
This commit is contained in:
@ -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'),
|
||||
|
@ -1,13 +1,16 @@
|
||||
var moment = require('moment'),
|
||||
mongodb = require('mongodb'),
|
||||
nodemailer = require('nodemailer'),
|
||||
sanitizeHtml = require('sanitize-html'),
|
||||
MongoClient = mongodb.MongoClient,
|
||||
resources = require('./resources'),
|
||||
secrets = require('../config/secrets'),
|
||||
/* eslint-disable no-catch-shadow, no-unused-vars */
|
||||
var R = require('ramda'),
|
||||
debug = require('debug')('freecc:cntr:story'),
|
||||
Story = require('./../models/Story'),
|
||||
Comment = require('./../models/Comment'),
|
||||
User = require('./../models/User');
|
||||
User = require('./../models/User'),
|
||||
moment = require('moment'),
|
||||
resources = require('./resources'),
|
||||
mongodb = require('mongodb'),
|
||||
MongoClient = mongodb.MongoClient,
|
||||
secrets = require('../config/secrets'),
|
||||
nodemailer = require('nodemailer'),
|
||||
sanitizeHtml = require('sanitize-html');
|
||||
|
||||
function hotRank(timeValue, rank) {
|
||||
/*
|
||||
@ -227,14 +230,13 @@ exports.upvote = function(req, res, next) {
|
||||
);
|
||||
story.markModified('rank');
|
||||
story.save();
|
||||
User.find({ '_id': story.author.userId }, function(err, user) {
|
||||
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) {
|
||||
req.user.save(function (err) {
|
||||
user.save(function (err, user) {
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@ -336,9 +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);
|
||||
}
|
||||
@ -383,7 +383,7 @@ exports.storySubmission = function(req, res, next) {
|
||||
return res.status(500);
|
||||
}
|
||||
req.user.progressTimestamps.push(Date.now() || 0);
|
||||
req.user.save(function (err) {
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@ -392,8 +392,7 @@ exports.storySubmission = function(req, res, next) {
|
||||
storyLink: story.storyLink.replace(/\s/g, '-').toLowerCase()
|
||||
}));
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
exports.commentSubmit = function(req, res, next) {
|
||||
@ -515,9 +514,7 @@ exports.storySubmission = function(req, res, next) {
|
||||
try {
|
||||
// Based on the context retrieve the parent
|
||||
// object of the comment (Story/Comment)
|
||||
Context.find(
|
||||
{ '_id': data.associatedPost },
|
||||
function (err, associatedContext) {
|
||||
Context.find({'_id': data.associatedPost}, function (err, associatedContext) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@ -532,9 +529,7 @@ exports.storySubmission = function(req, res, next) {
|
||||
});
|
||||
}
|
||||
// Find the author of the parent object
|
||||
User.findOne(
|
||||
{ 'profile.username': associatedContext.author.username },
|
||||
function(err, recipient) {
|
||||
User.findOne({'profile.username': associatedContext.author.username}, function(err, recipient) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@ -578,11 +573,10 @@ exports.storySubmission = function(req, res, next) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
// delete comment
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user