@@ -250,8 +250,17 @@ Generator.prototype.askForMongo = function askForMongo() {
250250 name : 'mongo' ,
251251 message : 'Would you like to include MongoDB with Mongoose?' ,
252252 default : false
253+ } , {
254+ type : 'confirm' ,
255+ name : 'mongoPassportUser' ,
256+ message : 'Would you like to include a Passport authentication boilerplate?' ,
257+ default : false ,
258+ when : function ( props ) {
259+ return props . mongo ;
260+ }
253261 } ] , function ( props ) {
254262 this . mongo = props . mongo ;
263+ this . mongoPassportUser = props . mongoPassportUser ;
255264
256265 cb ( ) ;
257266 } . bind ( this ) ) ;
@@ -335,21 +344,24 @@ function appendFilesToJade(jadeOrOptions, fileType, optimizedPath, sourceFileLis
335344 return updatedContent ;
336345}
337346
338- Generator . prototype . navBarScript = function navBarScript ( ) {
339- var ext = 'js' ;
340- var folder = 'javascript' ;
341- var minsafe = '' ;
347+ var copyScriptWithEnvOptions = function copyScriptWithEnvOptions ( that , fileToCopy , destinationFolder ) {
348+ var ext = 'js' ,
349+ minsafe = '' ,
350+ sourceFolder = 'javascript ' ;
342351
343- if ( this . env . options . coffee ) {
352+ if ( that . env . options . coffee ) {
344353 ext = 'coffee' ;
345- folder = 'coffeescript' ;
354+ sourceFolder = 'coffeescript' ;
346355 }
347356
348- if ( this . env . options . minsafe ) {
357+ if ( that . env . options . minsafe ) {
349358 minsafe = '-min' ;
350359 }
360+ that . copy ( '../../templates/' + sourceFolder + minsafe + '/' + fileToCopy + '.' + ext , destinationFolder + fileToCopy + '.' + ext ) ;
361+ } ;
351362
352- this . copy ( '../../templates/' + folder + minsafe + '/navbar.' + ext , 'app/scripts/controllers/navbar.' + ext ) ;
363+ Generator . prototype . navBarScript = function navBarScript ( ) {
364+ copyScriptWithEnvOptions ( this , 'controllers/navbar' , 'app/scripts/' ) ;
353365} ;
354366
355367Generator . prototype . appJs = function appJs ( ) {
@@ -360,6 +372,18 @@ Generator.prototype.appJs = function appJs() {
360372 sourceFileList : [ 'scripts/app.js' , 'scripts/controllers/main.js' , 'scripts/controllers/navbar.js' ] ,
361373 searchPath : [ '.tmp' , 'app' ]
362374 } ;
375+
376+ // only reference authentication controllers when required
377+ if ( this . mongoPassportUser ) {
378+ appendOptions . sourceFileList . push ( 'scripts/controllers/login.js' ) ;
379+ appendOptions . sourceFileList . push ( 'scripts/controllers/signup.js' ) ;
380+ appendOptions . sourceFileList . push ( 'scripts/controllers/settings.js' ) ;
381+ appendOptions . sourceFileList . push ( 'scripts/services/auth.js' ) ;
382+ appendOptions . sourceFileList . push ( 'scripts/services/session.js' ) ;
383+ appendOptions . sourceFileList . push ( 'scripts/services/user.js' ) ;
384+ appendOptions . sourceFileList . push ( 'scripts/directives/mongooseError.js' ) ;
385+ }
386+
363387 if ( this . jade ) {
364388 this . indexFile = appendFilesToJade ( appendOptions ) ;
365389 } else {
@@ -380,6 +404,11 @@ Generator.prototype.addJadeViews = function addHtmlJade() {
380404 if ( this . jade ) {
381405 this . copy ( '../../templates/views/jade/partials/main.jade' , 'app/views/partials/main.jade' ) ;
382406 this . copy ( '../../templates/views/jade/partials/navbar.jade' , 'app/views/partials/navbar.jade' ) ;
407+ if ( this . mongoPassportUser ) {
408+ this . copy ( '../../templates/views/jade/partials/login.jade' , 'app/views/partials/login.jade' ) ;
409+ this . copy ( '../../templates/views/jade/partials/signup.jade' , 'app/views/partials/signup.jade' ) ;
410+ this . copy ( '../../templates/views/jade/partials/settings.jade' , 'app/views/partials/settings.jade' ) ;
411+ }
383412 this . copy ( '../../templates/views/jade/404.jade' , 'app/views/404.jade' ) ;
384413 }
385414} ;
@@ -388,6 +417,11 @@ Generator.prototype.addHtmlViews = function addHtmlViews() {
388417 if ( ! this . jade ) {
389418 this . copy ( '../../templates/views/html/partials/main.html' , 'app/views/partials/main.html' ) ;
390419 this . copy ( '../../templates/views/html/partials/navbar.html' , 'app/views/partials/navbar.html' ) ;
420+ if ( this . mongoPassportUser ) {
421+ this . copy ( '../../templates/views/html/partials/login.html' , 'app/views/partials/login.html' ) ;
422+ this . copy ( '../../templates/views/html/partials/signup.html' , 'app/views/partials/signup.html' ) ;
423+ this . copy ( '../../templates/views/html/partials/settings.html' , 'app/views/partials/settings.html' ) ;
424+ }
391425 this . copy ( '../../templates/views/html/404.html' , 'app/views/404.html' ) ;
392426 }
393427} ;
@@ -443,11 +477,39 @@ Generator.prototype.serverFiles = function () {
443477} ;
444478
445479Generator . prototype . mongoFiles = function ( ) {
480+
446481 if ( ! this . mongo ) {
447482 return ; // Skip if disabled.
448483 }
484+ this . env . options . mongo = this . mongo ;
449485
450486 this . template ( '../../templates/express/mongo/mongo.js' , 'lib/db/mongo.js' ) ;
451487 this . template ( '../../templates/express/mongo/dummydata.js' , 'lib/db/dummydata.js' ) ;
452488 this . template ( '../../templates/express/mongo/thing.js' , 'lib/models/thing.js' ) ;
489+
490+ if ( ! this . mongoPassportUser ) {
491+ return ; // Skip if disabled.
492+ }
493+ this . env . options . mongoPassportUser = this . mongoPassportUser ;
494+
495+ // frontend
496+ copyScriptWithEnvOptions ( this , 'controllers/login' , 'app/scripts/' ) ;
497+ copyScriptWithEnvOptions ( this , 'controllers/signup' , 'app/scripts/' ) ;
498+ copyScriptWithEnvOptions ( this , 'controllers/settings' , 'app/scripts/' ) ;
499+
500+ copyScriptWithEnvOptions ( this , 'services/auth' , 'app/scripts/' ) ;
501+ copyScriptWithEnvOptions ( this , 'services/session' , 'app/scripts/' ) ;
502+ copyScriptWithEnvOptions ( this , 'services/user' , 'app/scripts/' ) ;
503+
504+ copyScriptWithEnvOptions ( this , 'directives/mongooseError' , 'app/scripts/' ) ;
505+
506+ // middleware
507+ this . template ( '../../templates/express/middleware.js' , 'lib/middleware.js' ) ;
508+ // config
509+ this . template ( '../../templates/express/config/passport.js' , 'lib/config/passport.js' ) ;
510+ // models
511+ this . template ( '../../templates/express/mongo/user.js' , 'lib/models/user.js' ) ;
512+ // controllers
513+ this . template ( '../../templates/express/session.js' , 'lib/controllers/session.js' ) ;
514+ this . template ( '../../templates/express/users.js' , 'lib/controllers/users.js' ) ;
453515} ;
0 commit comments