18.05.2016 Views

Mittwoch, 18. Mai, 2016

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Finishing Angular TODO application and deploying to production 118<br />

71 exports.logout = function(req, res) {<br />

72 req.logout();<br />

73 res.redirect('/');<br />

74 };<br />

75<br />

76 exports.saveOAuthUserProfile = function(req, profile, done) {<br />

77 User.findOne({<br />

78 provider: profile.provider,<br />

79 providerId: profile.providerId<br />

80 },<br />

81 function(err, user) {<br />

82 if (err) {<br />

83 return done(err);<br />

84 } else {<br />

85 if (!user) {<br />

86 var possibleUsername = profile.username || ((profile.email<br />

87 .split('@')[0] : '');<br />

88 User.findUniqueUsername(possibleUsername, null, function(a<br />

89 {<br />

90 profile.username = availableUsername;<br />

91 user = new User(profile);<br />

92<br />

93 user.save(function(err) {<br />

94 if (err) {<br />

95 var message = _this.getErrorMessag<br />

96 req.flash('error', message);<br />

97 return res.redirect('/register');<br />

98 }<br />

99<br />

100 return done(err, user);<br />

101 });<br />

102 });<br />

103 } else {<br />

104 return done(err, user);<br />

105 }<br />

106 }<br />

107 }<br />

108 );<br />

109 };<br />

110<br />

111<br />

112

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!