Skip to content

Commit

Permalink
flatten user object references throughout controllers and views
Browse files Browse the repository at this point in the history
  • Loading branch information
Quincy Larson committed Jun 4, 2015
1 parent db37482 commit b2aafd8
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 128 deletions.
78 changes: 39 additions & 39 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r
if (err) { return done(err); }
user.facebook = profile.id;
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
user.profile.name = user.profile.name || profile.displayName;
user.profile.gender = user.profile.gender || profile._json.gender;
user.profile.picture = user.profile.picture || 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
user.name = user.name || profile.displayName;
user.gender = user.gender || profile._json.gender;
user.picture = user.picture || 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
user.save(function(err) {
if (err) { return done(err); }
req.flash('info', { msg: 'Facebook account has been linked.' });
Expand All @@ -91,10 +91,10 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r
user.email = profile._json.email;
user.facebook = profile.id;
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
user.profile.name = profile.displayName;
user.profile.gender = profile._json.gender;
user.profile.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
user.profile.location = (profile._json.location) ? profile._json.location.name : '';
user.name = profile.displayName;
user.gender = profile._json.gender;
user.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
user.location = (profile._json.location) ? profile._json.location.name : '';
user.save(function(err) {
done(err, user);
var transporter = nodemailer.createTransport({
Expand Down Expand Up @@ -140,10 +140,10 @@ passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refre
User.findById(req.user.id, function(err, user) {
user.github = profile.id;
user.tokens.push({ kind: 'github', accessToken: accessToken });
user.profile.name = user.profile.name || profile.displayName;
user.profile.picture = user.profile.picture || profile._json.avatar_url;
user.profile.location = user.profile.location || profile._json.location;
user.profile.website = user.profile.website || profile._json.blog;
user.name = user.name || profile.displayName;
user.picture = user.picture || profile._json.avatar_url;
user.location = user.location || profile._json.location;
user.website = user.website || profile._json.blog;
user.save(function(err) {
if (err) { return done(err); }
req.flash('info', { msg: 'GitHub account has been linked.' });
Expand All @@ -166,10 +166,10 @@ passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refre
user.email = profile._json.email;
user.github = profile.id;
user.tokens.push({ kind: 'github', accessToken: accessToken });
user.profile.name = profile.displayName;
user.profile.picture = profile._json.avatar_url;
user.profile.location = profile._json.location;
user.profile.website = profile._json.blog;
user.name = profile.displayName;
user.picture = profile._json.avatar_url;
user.location = profile._json.location;
user.website = profile._json.blog;
user.save(function(err) {
if (err) { return done(err); }
var transporter = nodemailer.createTransport({
Expand Down Expand Up @@ -216,11 +216,11 @@ passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tok
User.findById(req.user.id, function(err, user) {
user.twitter = profile.id;
user.tokens.push({ kind: 'twitter', accessToken: accessToken, tokenSecret: tokenSecret });
user.profile.username = user.profile.username || profile.username.toLowerCase();
user.profile.name = user.profile.name || profile.displayName;
user.profile.location = user.profile.location || profile._json.location;
user.profile.picture = user.profile.picture || profile._json.profile_image_url_https.replace('_normal', '');
user.profile.twitterHandle = user.profile.twitterHandle || profile.username.toLowerCase();
user.username = user.username || profile.username.toLowerCase();
user.name = user.name || profile.displayName;
user.location = user.location || profile._json.location;
user.picture = user.picture || profile._json.profile_image_url_https.replace('_normal', '');
user.twitterHandle = user.twitterHandle || profile.username.toLowerCase();
user.save(function(err) {
if (err) { return done(err); }
req.flash('info', { msg: 'Twitter account has been linked.' });
Expand All @@ -235,13 +235,13 @@ passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tok
if (err) { return done(err); }
if (existingUser) return done(null, existingUser);
var user = new User();
user.profile.username = profile.username.toLowerCase();
user.username = profile.username.toLowerCase();
user.twitter = profile.id;
user.tokens.push({ kind: 'twitter', accessToken: accessToken, tokenSecret: tokenSecret });
user.profile.name = profile.displayName;
user.profile.location = profile._json.location;
user.profile.picture = profile._json.profile_image_url_https.replace('_normal', '');
user.profile.twitterHandle = user.profile.twitterHandle || profile.username.toLowerCase();
user.name = profile.displayName;
user.location = profile._json.location;
user.picture = profile._json.profile_image_url_https.replace('_normal', '');
user.twitterHandle = user.twitterHandle || profile.username.toLowerCase();
user.save(function(err) {
if (err) { return done(err); }
done(null, user);
Expand All @@ -264,9 +264,9 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
if (err) { return done(err); }
user.google = profile.id;
user.tokens.push({ kind: 'google', accessToken: accessToken });
user.profile.name = user.profile.name || profile.displayName;
user.profile.gender = user.profile.gender || profile._json.gender;
user.profile.picture = user.profile.picture || profile._json.picture;
user.name = user.name || profile.displayName;
user.gender = user.gender || profile._json.gender;
user.picture = user.picture || profile._json.picture;
user.save(function(err) {
if (err) { return done(err); }
req.flash('info', { msg: 'Google account has been linked.' });
Expand All @@ -289,9 +289,9 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
user.email = profile._json.email;
user.google = profile.id;
user.tokens.push({ kind: 'google', accessToken: accessToken });
user.profile.name = profile.displayName;
user.profile.gender = profile._json.gender;
user.profile.picture = profile._json.picture;
user.name = profile.displayName;
user.gender = profile._json.gender;
user.picture = profile._json.picture;
user.save(function(err) {
if (err) { return done(err); }
var transporter = nodemailer.createTransport({
Expand Down Expand Up @@ -339,10 +339,10 @@ passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, r
if (err) { return done(err); }
user.linkedin = profile.id;
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
user.profile.name = user.profile.name || profile.displayName;
user.profile.location = user.profile.location || profile._json.location.name;
user.profile.picture = user.profile.picture || profile._json.pictureUrl;
user.profile.website = user.profile.website || profile._json.publicProfileUrl;
user.name = user.name || profile.displayName;
user.location = user.location || profile._json.location.name;
user.picture = user.picture || profile._json.pictureUrl;
user.website = user.website || profile._json.publicProfileUrl;
user.save(function(err) {
if (err) { return done(err); }
req.flash('info', { msg: 'LinkedIn account has been linked.' });
Expand All @@ -364,10 +364,10 @@ passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, r
user.linkedin = profile.id;
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
user.email = profile._json.emailAddress;
user.profile.name = profile.displayName;
user.profile.location = profile._json.location.name;
user.profile.picture = profile._json.pictureUrl;
user.profile.website = profile._json.publicProfileUrl;
user.name = profile.displayName;
user.location = profile._json.location.name;
user.picture = profile._json.pictureUrl;
user.website = profile._json.publicProfileUrl;
user.save(function(err) {
if (err) { return done(err); }
var transporter = nodemailer.createTransport({
Expand Down
6 changes: 3 additions & 3 deletions public/js/main_0.0.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ profileValidation.controller('profileValidationController', ['$scope', '$http',
function($scope, $http) {
$http.get('/account/api').success(function(data) {
$scope.user = data.user;
$scope.user.profile.username = $scope.user.profile.username ? $scope.user.profile.username.toLowerCase() : undefined;
$scope.storedUsername = data.user.profile.username;
$scope.user.username = $scope.user.username ? $scope.user.username.toLowerCase() : undefined;
$scope.storedUsername = data.user.username;
$scope.storedEmail = data.user.email;
$scope.user.email = $scope.user.email ? $scope.user.email.toLowerCase() : undefined;
$scope.user.profile.twitterHandle = $scope.user.profile.twitterHandle ? $scope.user.profile.twitterHandle.toLowerCase() : undefined;
$scope.user.twitterHandle = $scope.user.twitterHandle ? $scope.user.twitterHandle.toLowerCase() : undefined;
$scope.asyncComplete = true;
});
}
Expand Down
4 changes: 2 additions & 2 deletions server/boot/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = function(app) {
app.use(router);

function index(req, res, next) {
if (req.user && !req.user.profile.picture) {
req.user.profile.picture =
if (req.user && !req.user.picture) {
req.user.picture =
'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';

req.user.save(function(err) {
Expand Down
6 changes: 3 additions & 3 deletions server/boot/nonprofits.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function(app) {
if (req.user.completedCoursewares.length > 63) {
var hasShownInterest =
nonprofit.interestedCampers.filter(function ( obj ) {
return obj.username === req.user.profile.username;
return obj.username === req.user.username;
});

if (hasShownInterest.length === 0) {
Expand Down Expand Up @@ -110,8 +110,8 @@ module.exports = function(app) {
function(err, nonprofit) {
if (err) { return next(err); }
nonprofit.interestedCampers.push({
username: req.user.profile.username,
picture: req.user.profile.picture,
username: req.user.username,
picture: req.user.picture,
timeOfInterest: Date.now()
});
nonprofit.save(function(err) {
Expand Down
6 changes: 3 additions & 3 deletions server/boot/randomAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module.exports = function(app) {


function getHelp(req, res) {
var userName = req.user.profile.username;
var userName = req.user.username;
var code = req.body.payload.code ? '\n```\n' +
req.body.payload.code + '\n```\n'
: '';
Expand All @@ -154,7 +154,7 @@ module.exports = function(app) {
}

function getPair(req, res) {
var userName = req.user.profile.username;
var userName = req.user.username;
var challenge = req.body.payload.challenge;
slack.send({
text: [
Expand Down Expand Up @@ -201,7 +201,7 @@ module.exports = function(app) {
} else {
Rx.Observable.from(users)
.map(function(user) {
return user.profile.username;
return user.username;
})
.toArray()
.subscribe(
Expand Down
16 changes: 8 additions & 8 deletions server/boot/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ module.exports = function(app) {
story.upVotes.push(
{
upVotedBy: req.user._id,
upVotedByUsername: req.user.profile.username
upVotedByUsername: req.user.username
}
);
story.markModified('rank');
Expand Down Expand Up @@ -397,12 +397,12 @@ module.exports = function(app) {
rank: 1,
upVotes: [({
upVotedBy: req.user._id,
upVotedByUsername: req.user.profile.username
upVotedByUsername: req.user.username
})],
author: {
picture: req.user.profile.picture,
picture: req.user.picture,
userId: req.user._id,
username: req.user.profile.username,
username: req.user.username,
email: req.user.email
},
comments: [],
Expand Down Expand Up @@ -452,9 +452,9 @@ module.exports = function(app) {
rank: 0,
upvotes: 0,
author: {
picture: req.user.profile.picture,
picture: req.user.picture,
userId: req.user._id,
username: req.user.profile.username,
username: req.user.username,
email: req.user.email
},
comments: [],
Expand Down Expand Up @@ -494,9 +494,9 @@ module.exports = function(app) {
originalStoryLink: data.originalStoryLink,
originalStoryAuthorEmail: data.originalStoryAuthorEmail,
author: {
picture: req.user.profile.picture,
picture: req.user.picture,
userId: req.user._id,
username: req.user.profile.username,
username: req.user.username,
email: req.user.email
},
comments: [],
Expand Down
Loading

0 comments on commit b2aafd8

Please sign in to comment.