Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. module.exports = function(passport) {
  2. passport.serializeUser(function(user, done) {
  3. done(null, user.id);
  4. });
  5. passport.deserializeUser(function(id, done) {
  6. User.findById(id, function(err, user) {
  7. done(err, user);
  8. });
  9. });
  10. passport.use(new FacebookStrategy({
  11. clientID : configAuth.facebookAuth.clientID,
  12. clientSecret : configAuth.facebookAuth.clientSecret,
  13. callbackURL : configAuth.facebookAuth.callbackURL,
  14. profileFields: ["emails", 'user_friends','manage_pages']
  15. },
  16. function(token, refreshToken, profile, done) {
  17. process.nextTick(function() {
  18.  
  19. User.findOne({ 'facebook.id' : profile.id }, function(err, user) {
  20. if (err)
  21. return done(err);
  22. if (user) {
  23. return done(null, user); // user found, return that user
  24. } else {
  25.  
  26. var newUser = new User();
  27. newUser.facebook.id = profile.id;
  28. newUser.facebook.token = token;
  29. newUser.facebook.name = profile.name;
  30. newUser.facebook.email = profile.emails[0].value;
  31. newUser.facebook.friends=profile.user_friends[5];
  32. newUser.save(function(err) {
  33. if (err)
  34. throw err;
  35. return done(null, newUser);
  36. });
  37. }
  38. });
  39. });
  40. }));
  41. };
  42.  
  43. var userSchema = mongoose.Schema({
  44. local: {
  45. username: String,
  46. password: String
  47. },
  48. facebook: {
  49. id: String,
  50. token: String,
  51. name1: String,
  52. email: String,
  53. friends:String
  54. }
  55. });
  56.  
  57. <div class="col-sm-6">
  58. <div class="well">
  59. <h3 class="text-primary"><span class="fa fa-facebook"></span> Facebook</h3>
  60.  
  61. <p>
  62. <strong>id</strong>: <%= user.facebook.id %><br>
  63. <strong>token</strong>: <%= user.facebook.token %><br>
  64. <strong>email</strong>: <%= user.facebook.email %><br>
  65. <strong>name1</strong>: <%= user.facebook.name %><br>
  66. <strong>Friends</strong>: <%= user.facebook.friends %><br>
  67. </p>
  68.  
  69. </div>
  70. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement