Add/Remove app.js generated routes for Facebook and GitHub
This commit is contained in:
56
generator.js
56
generator.js
@ -134,7 +134,18 @@ inquirer.prompt({
|
||||
var app = fs.readFileSync(appFile).toString().split('\n');
|
||||
var secrets = fs.readFileSync(secretsFile).toString().split('\n');
|
||||
|
||||
if (_.contains(answer.auth, 'Facebook')) {
|
||||
/////////////////////////////
|
||||
// Facebook Authentication //
|
||||
/////////////////////////////
|
||||
|
||||
var facebookRoutes = M(function() {
|
||||
/***
|
||||
app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
|
||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
***/
|
||||
});
|
||||
var facebookStrategyRequire = "var FacebookStrategy = require('passport-facebook').Strategy;";
|
||||
var facebookStrategy = M(function() {
|
||||
/***
|
||||
@ -205,29 +216,35 @@ inquirer.prompt({
|
||||
});
|
||||
var facebookModel = ' facebook: String,';
|
||||
|
||||
if (_.contains(answer.auth, 'Facebook')) {
|
||||
if (passportConfig.indexOf(facebookStrategyRequire) < 0) {
|
||||
|
||||
// config/passport.js
|
||||
// Add Facebook to config/passport.js
|
||||
index = passportConfig.indexOf("var passport = require('passport');");
|
||||
passportConfig.splice(index + 1, 0, facebookStrategyRequire);
|
||||
index = passportConfig.indexOf('passport.deserializeUser(function(id, done) {');
|
||||
passportConfig.splice(index + 6, 0, facebookStrategy);
|
||||
fs.writeFileSync(passportConfigFile, passportConfig.join('\n'));
|
||||
|
||||
// views/account/login.jade
|
||||
// Add Facebook to views/account/login.jade
|
||||
loginTemplate.push(facebookButton);
|
||||
fs.writeFileSync(loginTemplateFile, loginTemplate.join('\n'));
|
||||
|
||||
// views/account/profile.jade
|
||||
// Add Facebook to views/account/profile.jade
|
||||
index = profileTemplate.indexOf(' h3 Linked Accounts');
|
||||
profileTemplate.splice(index + 1, 0, facebookLinkUnlink);
|
||||
fs.writeFileSync(profileTemplateFile, profileTemplate.join('\n'));
|
||||
|
||||
// models/User.js
|
||||
// Add Facebook to models/User.js
|
||||
index = userModel.indexOf(' tokens: Array,');
|
||||
userModel.splice(index - 1, 0, facebookModel);
|
||||
fs.writeFileSync(userModelFile, userModel.join('\n'));
|
||||
|
||||
// Add Facebook to app.js
|
||||
index = app.indexOf(' * OAuth routes for sign-in.');
|
||||
app.splice(index + 3, 0, facebookRoutes);
|
||||
fs.writeFileSync(appFile, app.join('\n'));
|
||||
|
||||
console.log('✓ Facebook authentication has been added.'.info);
|
||||
} else {
|
||||
console.log('✓ Facebook authentication is already active.'.data);
|
||||
@ -256,10 +273,26 @@ inquirer.prompt({
|
||||
userModel.splice(index, 1);
|
||||
fs.writeFileSync(userModelFile, userModel.join('\n'));
|
||||
|
||||
// Remove Facebook from app.js
|
||||
index = app.indexOf("app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));");
|
||||
app.splice(index, 4);
|
||||
fs.writeFileSync(appFile, app.join('\n'));
|
||||
|
||||
console.log('✗ Facebook authentication has been removed.'.error);
|
||||
}
|
||||
|
||||
if (_.contains(answer.auth, 'GitHub')) {
|
||||
///////////////////////////
|
||||
// GitHub Authentication //
|
||||
///////////////////////////
|
||||
|
||||
var githubRoutes = M(function() {
|
||||
/***
|
||||
app.get('/auth/github', passport.authenticate('github'));
|
||||
app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
***/
|
||||
});
|
||||
var githubStrategyRequire = "var GitHubStrategy = require('passport-github').Strategy;";
|
||||
var githubStrategy = M(function() {
|
||||
/***
|
||||
@ -332,6 +365,7 @@ inquirer.prompt({
|
||||
});
|
||||
var githubModel = ' github: String,';
|
||||
|
||||
if (_.contains(answer.auth, 'GitHub')) {
|
||||
if (passportConfig.indexOf(githubStrategyRequire) < 0) {
|
||||
|
||||
// config/passport.js
|
||||
@ -355,6 +389,11 @@ inquirer.prompt({
|
||||
userModel.splice(index - 1, 0, githubModel);
|
||||
fs.writeFileSync(userModelFile, userModel.join('\n'));
|
||||
|
||||
// Add GitHub to app.js
|
||||
index = app.indexOf(' * OAuth routes for sign-in.');
|
||||
app.splice(index + 3, 0, githubRoutes);
|
||||
fs.writeFileSync(appFile, app.join('\n'));
|
||||
|
||||
console.log('✓ GitHub authentication has been added.'.info);
|
||||
} else {
|
||||
console.log('✓ GitHub authentication is already active.'.data);
|
||||
@ -383,6 +422,11 @@ inquirer.prompt({
|
||||
userModel.splice(index, 1);
|
||||
fs.writeFileSync(userModelFile, userModel.join('\n'));
|
||||
|
||||
// Remove GitHub from app.js
|
||||
index = app.indexOf("app.get('/auth/github', passport.authenticate('github'));");
|
||||
app.splice(index, 4);
|
||||
fs.writeFileSync(appFile, app.join('\n'));
|
||||
|
||||
console.log('✗ GitHub authentication has been removed.'.error);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user