Cleanup instagram generated code in secrets.js and app.js
This commit is contained in:
130
generator.js
130
generator.js
@ -637,6 +637,14 @@ inquirer.prompt({
|
|||||||
// LinkedIn Authentication //
|
// LinkedIn Authentication //
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
|
var linkedinRoutes = M(function() {
|
||||||
|
/***
|
||||||
|
app.get('/auth/linkedin', passport.authenticate('linkedin', { state: 'SOME STATE' }));
|
||||||
|
app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { failureRedirect: '/login' }), function(req, res) {
|
||||||
|
res.redirect(req.session.returnTo || '/');
|
||||||
|
});
|
||||||
|
***/
|
||||||
|
});
|
||||||
var linkedinStrategyRequire = "var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;";
|
var linkedinStrategyRequire = "var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;";
|
||||||
var linkedinStrategy = M(function() {
|
var linkedinStrategy = M(function() {
|
||||||
/***
|
/***
|
||||||
@ -897,83 +905,83 @@ inquirer.prompt({
|
|||||||
|
|
||||||
var instagramRoutes = M(function() {
|
var instagramRoutes = M(function() {
|
||||||
/***
|
/***
|
||||||
app.get('/auth/instagram', passport.authenticate('instagram'));
|
app.get('/auth/instagram', passport.authenticate('instagram'));
|
||||||
app.get('/auth/instagram/callback', passport.authenticate('instagram', { failureRedirect: '/login' }), function(req, res) {
|
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',
|
||||||
callbackURL: '/auth/instagram/callback',
|
callbackURL: '/auth/instagram/callback',
|
||||||
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) {
|
||||||
req.flash('errors', { msg: 'There is already an Instagram account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
req.flash('errors', { msg: 'There is already an Instagram account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
||||||
done(err);
|
done(err);
|
||||||
} else {
|
} else {
|
||||||
User.findById(req.user.id, function(err, user) {
|
User.findById(req.user.id, function(err, user) {
|
||||||
user.instagram = profile.id;
|
user.instagram = profile.id;
|
||||||
user.tokens.push({ kind: 'instagram', accessToken: accessToken });
|
user.tokens.push({ kind: 'instagram', accessToken: accessToken });
|
||||||
user.profile.name = user.profile.name || profile.displayName;
|
user.profile.name = user.profile.name || profile.displayName;
|
||||||
user.profile.picture = user.profile.picture || profile._json.data.profile_picture;
|
user.profile.picture = user.profile.picture || profile._json.data.profile_picture;
|
||||||
user.profile.website = user.profile.website || profile._json.data.website;
|
user.profile.website = user.profile.website || profile._json.data.website;
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
req.flash('info', { msg: 'Instagram account has been linked.' });
|
req.flash('info', { msg: 'Instagram account has been linked.' });
|
||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
User.findOne({ instagram: profile.id }, function(err, existingUser) {
|
|
||||||
if (existingUser) return done(null, existingUser);
|
|
||||||
|
|
||||||
var user = new User();
|
|
||||||
user.instagram = profile.id;
|
|
||||||
user.tokens.push({ kind: 'instagram', accessToken: accessToken });
|
|
||||||
user.profile.name = profile.displayName;
|
|
||||||
user.email = '';
|
|
||||||
user.profile.website = profile._json.data.website;
|
|
||||||
user.profile.picture = profile._json.data.profile_picture;
|
|
||||||
user.save(function(err) {
|
|
||||||
done(err, user);
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}));
|
} else {
|
||||||
|
User.findOne({ instagram: profile.id }, function(err, existingUser) {
|
||||||
|
if (existingUser) return done(null, existingUser);
|
||||||
|
|
||||||
***/
|
var user = new User();
|
||||||
|
user.instagram = profile.id;
|
||||||
|
user.tokens.push({ kind: 'instagram', accessToken: accessToken });
|
||||||
|
user.profile.name = profile.displayName;
|
||||||
|
user.email = '';
|
||||||
|
user.profile.website = profile._json.data.website;
|
||||||
|
user.profile.picture = profile._json.data.profile_picture;
|
||||||
|
user.save(function(err) {
|
||||||
|
done(err, user);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
***/
|
||||||
});
|
});
|
||||||
|
|
||||||
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
|
if user.instagram
|
||||||
p: a.text-danger(href='/account/unlink/instagram') Unlink your Instagram account
|
p: a.text-danger(href='/account/unlink/instagram') Unlink your Instagram account
|
||||||
else
|
else
|
||||||
p: a(href='/auth/instagram') Link your Instagram account
|
p: a(href='/auth/instagram') Link your Instagram account
|
||||||
***/
|
***/
|
||||||
});
|
});
|
||||||
var instagramModel = ' instagram: String,';
|
var instagramModel = ' instagram: String,';
|
||||||
@ -1039,6 +1047,16 @@ inquirer.prompt({
|
|||||||
profileTemplate.splice(index - 1, 5);
|
profileTemplate.splice(index - 1, 5);
|
||||||
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
|
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
|
||||||
|
|
||||||
|
// Remove Instagram from app.js
|
||||||
|
index = app.indexOf("app.get('/auth/instagram', passport.authenticate('instagram'));");
|
||||||
|
app.splice(index, 4);
|
||||||
|
fs.writeFileSync(appFile, app.join('\n'));
|
||||||
|
|
||||||
|
// Remove Instagram from secrets.js
|
||||||
|
index = secrets.indexOf(' instagram: {');
|
||||||
|
secrets.splice(index, 7);
|
||||||
|
fs.writeFileSync(secretsFile, secrets.join('\n'));
|
||||||
|
|
||||||
// Remove Instagram from User.js
|
// Remove Instagram from User.js
|
||||||
index = userModel.indexOf(' instagram: String,');
|
index = userModel.indexOf(' instagram: String,');
|
||||||
userModel.splice(index, 1);
|
userModel.splice(index, 1);
|
||||||
|
Reference in New Issue
Block a user