From ec5c542d07d7e160bb5269ec469f5967aa7cde91 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Fri, 1 May 2015 21:32:24 -0700 Subject: [PATCH] potentially fix the too many redirects issue --- controllers/home.js | 8 +++++++- controllers/user.js | 2 +- views/partials/navbar.jade | 18 +++++------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/controllers/home.js b/controllers/home.js index 27768a51eb..4c276db8f5 100644 --- a/controllers/home.js +++ b/controllers/home.js @@ -3,7 +3,13 @@ * Home page. */ -exports.index = function(req, res) { +exports.index = function(req, res, next) { + if (req.user && !req.user.profile.picture) { + req.user.profile.picture = 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png'; + req.user.save(function(err) { + if (err) { return next(err); } + }); + } res.render('home', { title: 'Learn to Code JavaScript and get a Coding Job by Helping Nonprofits' }); diff --git a/controllers/user.js b/controllers/user.js index c00a0a1f6d..8c6c62fa7d 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -55,7 +55,7 @@ exports.postSignin = function(req, res, next) { return next(err); } req.flash('success', { msg: 'Success! You are logged in.' }); - res.redirect(req.session.returnTo || '/'); + return res.redirect(req.session.returnTo || '/'); }); })(req, res, next); }; diff --git a/views/partials/navbar.jade b/views/partials/navbar.jade index ff2ce4dae3..e9b92721bd 100644 --- a/views/partials/navbar.jade +++ b/views/partials/navbar.jade @@ -41,17 +41,9 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height else a(href='/account') [ #{user.progressTimestamps.length} ] .hidden-xs.hidden-sm - if user.profile.picture - if (user.profile.username) - a(href='/' + user.profile.username) - img.profile-picture.float-right(src='#{user.profile.picture}') - else - a(href='/account') - img.profile-picture.float-right(src='#{user.profile.picture}') + if (user.profile.username) + a(href='/' + user.profile.username) + img.profile-picture.float-right(src='#{user.profile.picture}') else - if (user.profile.username) - a(href='/' + user.profile.username) - img.profile-picture.float-right(src='#{user.gravatar(60)}') - else - a(href='/account') - img.profile-picture.float-right(src='#{user.gravatar(60)}') + a(href='/account') + img.profile-picture.float-right(src='#{user.profile.picture}')