Removed duplicate linkedin generator code, plus other bug fixes.

This commit is contained in:
Sahat Yalkabov
2014-04-15 11:20:15 -04:00
parent 48792ce753
commit fa92443e03

View File

@ -633,13 +633,16 @@ inquirer.prompt({
console.log('✗ Twitter authentication has been removed.'.error); console.log('✗ Twitter authentication has been removed.'.error);
} }
if (_.contains(answer.auth, 'LinkedIn')) { /////////////////////////////
var linkedinStrategyRequire = "var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;"; // LinkedIn Authentication //
var linkedinStrategy = M(function() { /////////////////////////////
/***
// Sign in with LinkedIn.
passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, refreshToken, profile, done) { var linkedinStrategyRequire = "var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;";
var linkedinStrategy = M(function() {
/***
// Sign in with LinkedIn.
passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, refreshToken, profile, done) {
if (req.user) { if (req.user) {
User.findOne({ $or: [ User.findOne({ $or: [
{ linkedin: profile.id }, { linkedin: profile.id },
@ -687,156 +690,28 @@ inquirer.prompt({
}); });
} }
})); }));
***/ ***/
}); });
var linkedinButton = M(function() { var linkedinButton = M(function() {
/*** /***
a.btn.btn-block.btn-linkedin.btn-social(href='/auth/linkedin') a.btn.btn-block.btn-linkedin.btn-social(href='/auth/linkedin')
i.fa.fa-linkedin
| Sign in with LinkedIn
***/
});
var linkedinLinkUnlink = M(function() {
/***
if user.linkedin
p: a.text-danger(href='/account/unlink/linkedin') Unlink your LinkedIn account
else
p: a(href='/auth/linkedin') Link your LinkedIn account
***/
});
var linkedinModel = ' linkedin: String,';
if (passportConfig.indexOf(linkedinStrategyRequire) < 0) {
// config/passport.js (+)
index = passportConfig.indexOf("var passport = require('passport');");
passportConfig.splice(index + 1, 0, linkedinStrategyRequire);
index = passportConfig.indexOf('passport.deserializeUser(function(id, done) {');
passportConfig.splice(index + 6, 0, linkedinStrategy);
fs.writeFileSync(passportConfigFile, passportConfig.join('\n'));
// views/account/login.jade (+)
loginTemplate.push(linkedinButton);
fs.writeFileSync(loginTemplateFile, loginTemplate.join('\n'));
// views/account/profile.jade (+)
index = profileTemplate.indexOf(' h3 Linked Accounts');
profileTemplate.splice(index + 1, 0, linkedinLinkUnlink);
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
// models/User.js (+)
index = userModel.indexOf(' tokens: Array,');
userModel.splice(index - 1, 0, linkedinModel);
fs.writeFileSync(userModelFile, userModel.join('\n'));
console.log('✓ LinkedIn authentication has been added.'.info);
} else {
console.log('✓ LinkedIn authentication is already active.'.data);
}
} else {
// config/passport.js (-)
index = passportConfig.indexOf(linkedinStrategyRequire);
passportConfig.splice(index, 1);
index = passportConfig.indexOf('// Sign in with LinkedIn.');
passportConfig.splice(index, 51);
fs.writeFileSync(passportConfigFile, passportConfig.join('\n'));
// views/account/login.jade (-)
index = loginTemplate.indexOf(" a.btn.btn-block.btn-linkedin.btn-social(href='/auth/linkedin')");
loginTemplate.splice(index, 4);
fs.writeFileSync(loginTemplateFile, loginTemplate.join('\n'));
// views/account/profile.jade (-)
index = profileTemplate.indexOf(' if user.linkedin');
profileTemplate.splice(index - 1, 5);
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
// models/User.js (-)
index = userModel.indexOf(' linkedin: String,');
userModel.splice(index, 1);
fs.writeFileSync(userModelFile, userModel.join('\n'));
console.log('✗ LinkedIn authentication has been removed.'.error);
}
if (_.contains(answer.auth, 'LinkedIn')) {
var linkedinStrategyRequire = "var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;";
var linkedinStrategy = M(function() {
/***
// Sign in with LinkedIn.
passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, refreshToken, profile, done) {
if (req.user) {
User.findOne({ $or: [
{ linkedin: profile.id },
{ email: profile._json.emailAddress }
] }, function(err, existingUser) {
if (existingUser) {
req.flash('errors', { msg: 'There is already a LinkedIn account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
done(err);
} else {
User.findById(req.user.id, function(err, user) {
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.save(function(err) {
req.flash('info', { msg: 'LinkedIn account has been linked.' });
done(err, user);
});
});
}
});
} else {
User.findOne({ linkedin: profile.id }, function(err, existingUser) {
if (existingUser) return done(null, existingUser);
User.findOne({ email: profile._json.emailAddress }, function(err, existingEmailUser) {
if (existingEmailUser) {
req.flash('errors', { msg: 'There is already an account using this email address. Sign in to that account and link it with LinkedIn manually from Account Settings.' });
done(err);
} else {
var user = new User();
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.save(function(err) {
done(err, user);
});
}
});
});
}
}));
***/
});
var linkedinButton = M(function() {
/***
a.btn.btn-block.btn-linkedin.btn-social(href='/auth/linkedin')
i.fa.fa-linkedin i.fa.fa-linkedin
| Sign in with LinkedIn | Sign in with LinkedIn
***/ ***/
}); });
var linkedinLinkUnlink = M(function() { var linkedinLinkUnlink = M(function() {
/*** /***
if user.linkedin if user.linkedin
p: a.text-danger(href='/account/unlink/linkedin') Unlink your LinkedIn account p: a.text-danger(href='/account/unlink/linkedin') Unlink your LinkedIn account
else else
p: a(href='/auth/linkedin') Link your LinkedIn account p: a(href='/auth/linkedin') Link your LinkedIn account
***/ ***/
}); });
var linkedinModel = ' linkedin: String,'; var linkedinModel = ' linkedin: String,';
if (_.contains(answer.auth, 'LinkedIn')) {
if (passportConfig.indexOf(linkedinStrategyRequire) < 0) { if (passportConfig.indexOf(linkedinStrategyRequire) < 0) {
// config/passport.js (+) // config/passport.js (+)
@ -866,24 +741,27 @@ inquirer.prompt({
} }
} else { } else {
// config/passport.js (-) // Check if we have LinkedIn authentication to begin with.
if (passportConfig.indexOf(linkedinStrategyRequire) < 0) return;
// Removed LinkedIn from config/passport.js
index = passportConfig.indexOf(linkedinStrategyRequire); index = passportConfig.indexOf(linkedinStrategyRequire);
passportConfig.splice(index, 1); passportConfig.splice(index, 1);
index = passportConfig.indexOf('// Sign in with LinkedIn.'); index = passportConfig.indexOf('// Sign in with LinkedIn.');
passportConfig.splice(index, 51); passportConfig.splice(index, 51);
fs.writeFileSync(passportConfigFile, passportConfig.join('\n')); fs.writeFileSync(passportConfigFile, passportConfig.join('\n'));
// views/account/login.jade (-) // Remove LinkedIn from login.jade
index = loginTemplate.indexOf(" a.btn.btn-block.btn-linkedin.btn-social(href='/auth/linkedin')"); index = loginTemplate.indexOf(" a.btn.btn-block.btn-linkedin.btn-social(href='/auth/linkedin')");
loginTemplate.splice(index, 4); loginTemplate.splice(index, 4);
fs.writeFileSync(loginTemplateFile, loginTemplate.join('\n')); fs.writeFileSync(loginTemplateFile, loginTemplate.join('\n'));
// views/account/profile.jade (-) // Remove LinkedIn from profile.jade
index = profileTemplate.indexOf(' if user.linkedin'); index = profileTemplate.indexOf(' if user.linkedin');
profileTemplate.splice(index - 1, 5); profileTemplate.splice(index - 1, 5);
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n')); fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
// models/User.js (-) // Remove LinkedIn from User.js
index = userModel.indexOf(' linkedin: String,'); index = userModel.indexOf(' linkedin: String,');
userModel.splice(index, 1); userModel.splice(index, 1);
fs.writeFileSync(userModelFile, userModel.join('\n')); fs.writeFileSync(userModelFile, userModel.join('\n'));
@ -1013,17 +891,20 @@ inquirer.prompt({
console.log('✗ Local authentication has been removed.'.error); console.log('✗ Local authentication has been removed.'.error);
} }
if (_.contains(answer.auth, 'Instagram')) { //////////////////////////////
var instagramRoutes = M(function() { // Instagram Authentication //
/*** //////////////////////////////
app.get('/auth/instagram', passport.authenticate('instagram'));
app.get('/auth/instagram/callback', passport.authenticate('instagram', { failureRedirect: '/login' }), function(req, res) { var instagramRoutes = M(function() {
/***
app.get('/auth/instagram', passport.authenticate('instagram'));
app.get('/auth/instagram/callback', passport.authenticate('instagram', { failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });
***/ ***/
}); });
var instagramSecrets = M(function() { var instagramSecrets = M(function() {
/*** /***
instagram: { instagram: {
clientID: process.env.INSTAGRAM_ID || 'Your Client ID', clientID: process.env.INSTAGRAM_ID || 'Your Client ID',
clientSecret: process.env.INSTAGRAM_SECRET || 'Your Client Secret', clientSecret: process.env.INSTAGRAM_SECRET || 'Your Client Secret',
@ -1031,14 +912,14 @@ inquirer.prompt({
passReqToCallback: true passReqToCallback: true
}, },
***/ ***/
}); });
var instagramStrategyRequire = "var InstagramStrategy = require('passport-instagram').Strategy;"; var instagramStrategyRequire = "var InstagramStrategy = require('passport-instagram').Strategy;";
var instagramStrategy = M(function() { var instagramStrategy = M(function() {
/*** /***
// Sign in with Instagram. // Sign in with Instagram.
passport.use(new InstagramStrategy(secrets.instagram,function(req, accessToken, refreshToken, profile, done) { passport.use(new InstagramStrategy(secrets.instagram,function(req, accessToken, refreshToken, profile, done) {
if (req.user) { if (req.user) {
User.findOne({ $or: [{ instagram: profile.id }, { email: profile.email }] }, function(err, existingUser) { User.findOne({ $or: [{ instagram: profile.id }, { email: profile.email }] }, function(err, existingUser) {
if (existingUser) { if (existingUser) {
@ -1076,26 +957,29 @@ inquirer.prompt({
} }
})); }));
***/ ***/
}); });
var instagramButton = M(function() { var instagramButton = M(function() {
/*** /***
a.btn.btn-block.btn-instagram.btn-social(href='/auth/instagram') a.btn.btn-block.btn-instagram.btn-social(href='/auth/instagram')
i.fa.fa-instagram i.fa.fa-instagram
| Sign in with Instagram | Sign in with Instagram
***/ ***/
}); });
var instagramLinkUnlink = M(function() { var instagramLinkUnlink = M(function() {
/*** /***
if user.instagram
p: a.text-danger(href='/account/unlink/instagram') Unlink your Instagram account
else
p: a(href='/auth/instagram') Link your Instagram account
***/
});
var instagramModel = ' instagram: String,';
if (_.contains(answer.auth, 'Instagram')) {
if user.instagram
p: a.text-danger(href='/account/unlink/instagram') Unlink your Instagram account
else
p: a(href='/auth/linkedin') Link your Instagram account
***/
});
var instagramModel = ' instagram: String,';
if (passportConfig.indexOf(instagramStrategyRequire) < 0) { if (passportConfig.indexOf(instagramStrategyRequire) < 0) {
@ -1136,6 +1020,8 @@ inquirer.prompt({
} }
} else { } else {
if (passportConfig.indexOf(instagramStrategyRequire) < 0) return;
// Remove Instagram from passport.js // Remove Instagram from passport.js
index = passportConfig.indexOf(instagramStrategyRequire); index = passportConfig.indexOf(instagramStrategyRequire);
passportConfig.splice(index, 1); passportConfig.splice(index, 1);