Removed duplicate linkedin generator code, plus other bug fixes.
This commit is contained in:
156
generator.js
156
generator.js
@ -633,7 +633,10 @@ inquirer.prompt({
|
||||
console.log('✗ Twitter authentication has been removed.'.error);
|
||||
}
|
||||
|
||||
if (_.contains(answer.auth, 'LinkedIn')) {
|
||||
/////////////////////////////
|
||||
// LinkedIn Authentication //
|
||||
/////////////////////////////
|
||||
|
||||
var linkedinStrategyRequire = "var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;";
|
||||
var linkedinStrategy = M(function() {
|
||||
/***
|
||||
@ -708,135 +711,7 @@ inquirer.prompt({
|
||||
});
|
||||
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
|
||||
| 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 (+)
|
||||
@ -866,24 +741,27 @@ inquirer.prompt({
|
||||
}
|
||||
} 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);
|
||||
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 (-)
|
||||
// Remove LinkedIn from 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 (-)
|
||||
// Remove LinkedIn from profile.jade
|
||||
index = profileTemplate.indexOf(' if user.linkedin');
|
||||
profileTemplate.splice(index - 1, 5);
|
||||
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
|
||||
|
||||
// models/User.js (-)
|
||||
// Remove LinkedIn from User.js
|
||||
index = userModel.indexOf(' linkedin: String,');
|
||||
userModel.splice(index, 1);
|
||||
fs.writeFileSync(userModelFile, userModel.join('\n'));
|
||||
@ -1013,7 +891,10 @@ inquirer.prompt({
|
||||
console.log('✗ Local authentication has been removed.'.error);
|
||||
}
|
||||
|
||||
if (_.contains(answer.auth, 'Instagram')) {
|
||||
//////////////////////////////
|
||||
// Instagram Authentication //
|
||||
//////////////////////////////
|
||||
|
||||
var instagramRoutes = M(function() {
|
||||
/***
|
||||
app.get('/auth/instagram', passport.authenticate('instagram'));
|
||||
@ -1092,11 +973,14 @@ inquirer.prompt({
|
||||
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
|
||||
p: a(href='/auth/instagram') Link your Instagram account
|
||||
***/
|
||||
});
|
||||
var instagramModel = ' instagram: String,';
|
||||
|
||||
if (_.contains(answer.auth, 'Instagram')) {
|
||||
|
||||
|
||||
if (passportConfig.indexOf(instagramStrategyRequire) < 0) {
|
||||
|
||||
// Add Instagram to passport.js
|
||||
@ -1136,6 +1020,8 @@ inquirer.prompt({
|
||||
}
|
||||
} else {
|
||||
|
||||
if (passportConfig.indexOf(instagramStrategyRequire) < 0) return;
|
||||
|
||||
// Remove Instagram from passport.js
|
||||
index = passportConfig.indexOf(instagramStrategyRequire);
|
||||
passportConfig.splice(index, 1);
|
||||
|
Reference in New Issue
Block a user