var contants = require('../constants');
var userController = require('./controllers/userController');
var passport = require('passport');
var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});

passport.use(new LinkedInStrategy({
    clientID:     contants.LINKEDIN_CLIENT_ID,
    clientSecret: contants.LINKEDIN_CLIENT_SECRET,
    callbackURL:  "http://127.0.0.1:8000/api/auth/linkedin/callback",
    scope:        [ 'r_basicprofile', 'r_emailaddress'],
    state: true
  },
  function(req, accessToken, refreshToken, profile, done) {
    process.nextTick(function () {
      userController
        .findByLinkedInId(profile.id)
        .then(function(user){
          if (user){
            return done(null, user);
          } else {
            userController.create({
              linkedinId: profile.id,
              email: profile._json.emailAddress,
              name: profile.displayName,
              picture: profile._json.pictureUrl,
              publicProfileUrl: profile._json.publicProfileUrl,
              headline: profile._json.headline,
              summary: profile._json.summary,
              location: profile._json.location.name
            })
            .then(function(newUser){
              return done(null, newUser);
            });
          }
        });
    });
  }
));

module.exports = passport;
@@ -824,32 +824,435 @@
      if (user)%7B%0A
+            user.email = profile._json.emailAddress;%0A            user.name = profile.displayName;%0A            user.picture = profile._json.pictureUrl;%0A            user.publicProfileUrl = profile._json.publicProfileUrl;%0A            user.headline = profile._json.headline;%0A            user.summary = profile._json.summary;%0A            user.location = profile._json.location.name;%0A            user.save();%0A
             retu

update profile on login