remove public accounts if user is not github cool or grandfathered

This commit is contained in:
Berkeley Martinez
2015-08-05 13:01:19 -07:00
parent 504239050c
commit f167238c74

View File

@ -122,13 +122,28 @@ module.exports = function(app) {
*/ */
function returnUser(req, res, next) { function returnUser(req, res, next) {
const username = req.params.username.toLowerCase();
const { path } = req;
User.findOne( User.findOne(
{ where: { 'username': req.params.username.toLowerCase() } }, { where: { username } },
function(err, user) { function(err, user) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (user) { if (!user) {
req.flash('errors', {
msg: `404: We couldn't find path ${ path }`
});
return res.redirect('/');
}
if (!user.isGithubCool && !user.isMigrationGrandfathered) {
req.flash('errors', {
msg: `
user ${ username } has not completed account signup
`
});
return res.redirect('/');
}
user.progressTimestamps = user.progressTimestamps =
user.progressTimestamps.sort(function(a, b) { user.progressTimestamps.sort(function(a, b) {
return a - b; return a - b;
@ -197,14 +212,13 @@ module.exports = function(app) {
user.currentStreak = user.currentStreak || 1; user.currentStreak = user.currentStreak || 1;
user.longestStreak = user.longestStreak || 1; user.longestStreak = user.longestStreak || 1;
var challenges = user.completedChallenges.filter(function( obj ) {
return obj.challengeType === 3 || obj.challengeType === 4;
});
res.render('account/show', { res.render('account/show', {
title: 'Camper ' + user.username + '\'s portfolio', title: 'Camper ' + user.username + '\'s portfolio',
username: user.username, username: user.username,
name: user.name, name: user.name,
isMigrationGrandfathered: user.isMigrationGrandfathered,
isGithubCool: user.isGithubCool,
location: user.location, location: user.location,
githubProfile: user.githubProfile, githubProfile: user.githubProfile,
linkedinProfile: user.linkedinProfile, linkedinProfile: user.linkedinProfile,
@ -214,7 +228,6 @@ module.exports = function(app) {
bio: user.bio, bio: user.bio,
picture: user.picture, picture: user.picture,
progressTimestamps: user.progressTimestamps, progressTimestamps: user.progressTimestamps,
challenges: challenges,
calender: data, calender: data,
moment: moment, moment: moment,
longestStreak: user.longestStreak + longestStreak: user.longestStreak +
@ -222,13 +235,6 @@ module.exports = function(app) {
currentStreak: user.currentStreak + currentStreak: user.currentStreak +
(user.currentStreak === 1 ? ' day' : ' days') (user.currentStreak === 1 ? ' day' : ' days')
}); });
} else {
req.flash('errors', {
msg: "404: We couldn't find a page with that url. " +
'Please double check the link.'
});
return res.redirect('/');
}
} }
); );
} }